Skip to content

Commit

Permalink
A messege is constructed and sent to the client (still through gmail)…
Browse files Browse the repository at this point in the history
… when ordering devices.
  • Loading branch information
arc12012 committed Apr 16, 2017
1 parent 488daa8 commit e6c1f94
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
3 changes: 1 addition & 2 deletions WebContent/html/webpages/redirect/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pageEncoding="ISO-8859-1"%>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@include file="navbar.jsp"%>
<%@include file="../components/navbar.jsp"%>
</nav>
<script type="text/javascript">
<%
Expand Down Expand Up @@ -69,7 +69,6 @@ for(int i=0; i<devIDs.length; i++)
boolean emailNotificationEnabled = true; //If/when we enable opting out of notifications this is where that check will take place
if(emailNotificationEnabled)
{
new Mail(self).sendTicketConfirmation(ticketIDs); //'self' is the current user, and is defined in navbar.jsp
}
%>
Expand Down
1 change: 1 addition & 0 deletions emails/ticketConfirmation.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- I would love to organize these templates better, but I have no idea where eclipse is putting everything when it builds the project -->
<!DOCTYPE html>
<html>
<head>
Expand Down
35 changes: 31 additions & 4 deletions src/utilities/Mail.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package utilities;

import java.awt.HeadlessException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
Expand All @@ -12,16 +17,38 @@

public class Mail {
private String sender = "arclaxton@gmail.com";
private String password = "*****";
private String password = "";
private User client;
public Mail(User client){
this.client=client;
}
//Sends an email to address specified by recipient param
// messegeIndex param is for choosing which
public void sendTicketConfirmation(int[] ticketIDs) {
public void sendTicketConfirmation(int[] ticketIDs) throws IOException, InterruptedException {
String subject = "Your test device order";
String msg = "";
// I really want to read this from a seperate file, but even when it's in the same directory eclipse insists on moving everything around :(
String msg = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
+ "<h4>We've received your order! We'll let you know when your device{s} ship{!s}.</h4>"
+ "<p>The following ticket{s} {was/were} generated:</p>"
+ "<div name = 'tickets' style='text-indent: 20px'>"
+ "{TICKETS GO HERE}"
+ "</div>"
+ "</body>"
+ "<footer style='text-align: center;'><font size='1'>To change notification settings, please visit your <a href='../WebContent/html/webpages/profileSettings.jsp'>profile settings page</a></font></footer>"
+ "</html>";

// The messege needs to be tailored to make sense
msg=msg.replace("{s}",(ticketIDs.length==1 ? "" : "s")); //make occurances of 'device' and 'ticket' plural or singular
msg=msg.replace("{was/were}",ticketIDs.length==1 ? "was" : "were"); //use appropriate verbs
msg=msg.replace("{!s}",ticketIDs.length==1 ? "s" : "s"); //verbs again
String tickethtml = "";
for(int tickID : ticketIDs)
{
tickethtml+="<p>Ticket #<a href='../WebContent/html/webpages/'>"+tickID+"</a></p>";
}
msg=msg.replace("{TICKETS GO HERE}",tickethtml);
Properties properties = System.getProperties();
properties = setProp(sender, client.getEmail());
Session session = Session.getInstance(properties, new Authenticator() {
Expand All @@ -36,7 +63,7 @@ protected PasswordAuthentication getPasswordAuthentication(){
message.setFrom(address);
message.addRecipient(Message.RecipientType.TO, address);
message.setSubject(subject);
message.setText(msg);
message.setText(msg,"utf-8","html");
message.saveChanges();
Transport.send(message);
System.out.println("Sent message successfully....");
Expand Down

0 comments on commit e6c1f94

Please sign in to comment.