Skip to content

Commit

Permalink
Added Mail class which can send an email from my gmail account
Browse files Browse the repository at this point in the history
Needs some work to be able to send messeges relevant to the project, and propbably needs modification to work with Synchrony's email.

Classpath was modified to include new libraries

Shopping cart remove all items messege fixed
  • Loading branch information
arc12012 committed Apr 13, 2017
1 parent 6c94b95 commit 92401ab
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 3 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/smtp.jar
Binary file not shown.
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 92401ab

Please sign in to comment.