Skip to content

Commit

Permalink
Merge branch 'email'
Browse files Browse the repository at this point in the history
  • Loading branch information
arc12012 committed Apr 13, 2017
2 parents fb495d4 + 92401ab commit ab2b332
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 4 deletions.
23 changes: 21 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/servlet-api.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
<classpathentry kind="lib" path="lib/servlet-api.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/activation.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/mail.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/smtp.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
Expand Down
Binary file added WebContent/WEB-INF/lib/activation.jar
Binary file not shown.
Binary file added WebContent/WEB-INF/lib/mail.jar
Binary file not shown.
Binary file added WebContent/WEB-INF/lib/servlet-api.jar
Binary file not shown.
Binary file added WebContent/WEB-INF/lib/smtp.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion WebContent/html/webpages/navbar.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ page import = "database.*,entities.User" %>
<%@ page import = "database.*,entities.User,utilities.Mail" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<div class="container-fluid">
<div class="navbar-header">
Expand All @@ -25,6 +25,11 @@
</ul>
</div>
<%
Mail mail = new Mail();
mail.send();
Cookie[] usercookies = request.getCookies();
String navsso = "invalid";
String navname = "error";
Expand Down
4 changes: 4 additions & 0 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ for(int i=0; i<devIDs.length; i++)
TicketQueries.generateTicket(Integer.parseInt(navsso), location, devIDs[i], request.getParameter("timeNeeded"));//TODO get ID somehow
}
// Now that tickets have been generated we will want to notify users.
%>
window.location.replace("shoppingCart.jsp");
</script>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ function selectAllDevices() {
This function takes all devices in the shopping cart and deletes them.
**/
function deleteAll(){
var response = confirm("Are you sure you'd like to order the selected items?");
var response = confirm("Are you sure you'd like to empty your cart?");
if(response == true){ //if they confirm
cart = new Array; //empty cart
localStorage.setItem('cart',JSON.stringify(cart)); //update local storage
Expand Down
Binary file added lib/activation.jar
Binary file not shown.
Binary file added lib/mail.jar
Binary file not shown.
Binary file added lib/smtp.jar
Binary file not shown.
67 changes: 67 additions & 0 deletions src/utilities/Mail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package utilities;

import java.awt.HeadlessException;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
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";
Properties properties = System.getProperties();
properties = setProp(from, to);
Session session = Session.getInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(from, password);
}
});

try {
Address address = new InternetAddress(to);
MimeMessage message = new MimeMessage(session);
message.setFrom(address);
message.addRecipient(Message.RecipientType.TO, address);
message.setSubject(subject);
message.setText(msg);
message.saveChanges();
Transport.send(message);
System.out.println("Sent message successfully....");

} catch (Exception mex) {
mex.printStackTrace();
}

}

private Properties setProp(String email, String targetEmail) {
Properties props = null;
try {
props = System.getProperties();
props.setProperty("mail.transport.protocol", "smtp");
if (email.contains(",") || targetEmail.contains(",")) {
System.out.println("Please send one email to one person at a time...");
} else if (email.contains("@gmail.com")) {
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
} else {
System.out.println("Your Email Address is invalid\n or host not supported!");
}

} catch (HeadlessException exp) {
System.out.println(exp);
}
return props;
}
}

0 comments on commit ab2b332

Please sign in to comment.