import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;
public class GmailSendEmailSSL {
public static final String USERNAME = "xxxxxxxxxxxxxxxx";
public static final String PASSWORD = "xxxxxxxxxxxxxxxx";
public static void main(String[] args) throws Exception {
//
// Email information such as from, to, subject and contents.
//
String mailFrom = "xxxxxxxxxxxxxxxxxxxxxx";
String mailTo = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
String mailSubject = "TestReport";
String mailText = "Please check enclosed TestReport";
GmailSendEmailSSL gmail = new GmailSendEmailSSL();
gmail.sendMail(mailFrom, mailTo, mailSubject, mailText);
}
private void sendMail(String mailFrom, String mailTo,
String mailSubject, String mailText)
throws Exception {
Properties config = createConfiguration();
//
// Creates a mail session. We need to supply username and
// password for Gmail authentication.
//
Session session = Session.getInstance(config, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
GmailSendEmailSSL.USERNAME,
GmailSendEmailSSL.PASSWORD
);
}
});
//
// Creates email message
//
Message message = new MimeMessage(session);
message.setSentDate(new Date());
message.setFrom(new InternetAddress(mailFrom));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
message.setSubject(mailSubject);
message.setText(mailText);
//
// Send a message
//
Transport.send(message);
}
private Properties createConfiguration() {
return new Properties() {{
put("mail.smtp.host", "smtp.gmail.com");
put("mail.smtp.auth", "true");
put("mail.smtp.port", "465");
put("mail.smtp.socketFactory.port", "465");
put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
}};
}
}
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;
public class GmailSendEmailSSL {
public static final String USERNAME = "xxxxxxxxxxxxxxxx";
public static final String PASSWORD = "xxxxxxxxxxxxxxxx";
public static void main(String[] args) throws Exception {
//
// Email information such as from, to, subject and contents.
//
String mailFrom = "xxxxxxxxxxxxxxxxxxxxxx";
String mailTo = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
String mailSubject = "TestReport";
String mailText = "Please check enclosed TestReport";
GmailSendEmailSSL gmail = new GmailSendEmailSSL();
gmail.sendMail(mailFrom, mailTo, mailSubject, mailText);
}
private void sendMail(String mailFrom, String mailTo,
String mailSubject, String mailText)
throws Exception {
Properties config = createConfiguration();
//
// Creates a mail session. We need to supply username and
// password for Gmail authentication.
//
Session session = Session.getInstance(config, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
GmailSendEmailSSL.USERNAME,
GmailSendEmailSSL.PASSWORD
);
}
});
//
// Creates email message
//
Message message = new MimeMessage(session);
message.setSentDate(new Date());
message.setFrom(new InternetAddress(mailFrom));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
message.setSubject(mailSubject);
message.setText(mailText);
//
// Send a message
//
Transport.send(message);
}
private Properties createConfiguration() {
return new Properties() {{
put("mail.smtp.host", "smtp.gmail.com");
put("mail.smtp.auth", "true");
put("mail.smtp.port", "465");
put("mail.smtp.socketFactory.port", "465");
put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
}};
}
}
It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..
ReplyDeleteCRO Agency in Chennai
Its a really great post.
ReplyDeleteBest SAP Training in Bangalore
Best Java Training in Bangalore
Informative post.I got more knowledge from this blog.Thanks for sharing.... Warehouse Audit
ReplyDeleteStock Audit
Customer Reconciliation
Nice Blog i can easily understand with coding
ReplyDeleteselenium training centers in Bangalore
best software testing training institutes in Bangalore with placements
automation testing courses in Bangalore
selenium testing course in Bangalore
software testing institutes in Bangalore
selenium training in Bangalore
best selenium training in Bangalore
selenium course in Bangalore
Nice blog
ReplyDeletetableau course in Marathahalli
best tableau training in Marathahalli
tableau training in Marathahalli
tableau training in Marathahalli
tableau certification in Marathahalli
tableau training institutes in Marathahalli
I really enjoyed your blog Thanks for sharing such an informative post.Looking For Some More Stuff.
ReplyDeleteshuttering works
such an amazing content.
ReplyDeletePackers and movers
Movers and packers
Packers and movers in gurgaon
Packers and movers in Delhi
Packers and movers in Noida