-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mail class which can send an email from my gmail account
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
Showing
7 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |