From 20f7ba524cafafc4cf4ae33c949c1a0ba895b603 Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Sun, 16 Apr 2017 14:21:48 -0400 Subject: [PATCH] Restructured Mail.java a bit and added ticket confirmation email template --- WebContent/html/webpages/orderFormHandler.jsp | 15 ++++++---- emails/ticketConfirmation.html | 15 ++++++++++ src/database/TicketQueries.java | 3 +- src/utilities/Mail.java | 29 +++++++++++-------- 4 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 emails/ticketConfirmation.html diff --git a/WebContent/html/webpages/orderFormHandler.jsp b/WebContent/html/webpages/orderFormHandler.jsp index 2b6fb02..c42eeb5 100644 --- a/WebContent/html/webpages/orderFormHandler.jsp +++ b/WebContent/html/webpages/orderFormHandler.jsp @@ -9,7 +9,7 @@ pageEncoding="ISO-8859-1"%> diff --git a/emails/ticketConfirmation.html b/emails/ticketConfirmation.html new file mode 100644 index 0000000..3be8f72 --- /dev/null +++ b/emails/ticketConfirmation.html @@ -0,0 +1,15 @@ + + + + + + +

We've received your order! We'll let you know when your device{s} will ship.

+

The following ticket{s} {was/were} generated:

+
+

Ticket #12321312

+

Ticket #12321312

+
+ + + \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 53ffa3d..3005bbd 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -10,7 +10,7 @@ public class TicketQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static void generateTicket(int requester, int location, int device, String returnDate) throws ClassNotFoundException, SQLException + public static int generateTicket(int requester, int location, int device, String returnDate) throws ClassNotFoundException, SQLException { long time = new Date().getTime(); //Using milliseconds because sql is annoying with dates. int ticketID = (int)((time+requester+device+location)%10000); @@ -34,6 +34,7 @@ public static void generateTicket(int requester, int location, int device, Strin stmt.executeUpdate(query); stmt.close(); connection.close(); + return ticketID; } //get all tickets diff --git a/src/utilities/Mail.java b/src/utilities/Mail.java index 674e0ab..3c00473 100644 --- a/src/utilities/Mail.java +++ b/src/utilities/Mail.java @@ -4,29 +4,34 @@ import java.util.*; import javax.mail.*; import javax.mail.internet.*; + +import entities.User; + import javax.activation.*; public class Mail { - - public Mail() { - } - public void email() { - String from = "arclaxton@gmail.com"; - String password = "*****"; - String to = "arclaxton@gmail.com"; - String subject = "test"; - String msg = "this is a test"; + private String sender = "arclaxton@gmail.com"; + 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) { + String subject = "Your test device order"; + String msg = ""; Properties properties = System.getProperties(); - properties = setProp(from, to); + properties = setProp(sender, client.getEmail()); Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(){ - return new PasswordAuthentication(from, password); + return new PasswordAuthentication(sender, password); } }); try { - Address address = new InternetAddress(to); + Address address = new InternetAddress(client.getEmail()); MimeMessage message = new MimeMessage(session); message.setFrom(address); message.addRecipient(Message.RecipientType.TO, address);