Last active
August 29, 2015 14:17
-
-
Save zerg000000/566f38484ba4ea4cba3e to your computer and use it in GitHub Desktop.
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
public class Mailer { | |
public void send(String content) { | |
String to = "[email protected]"; | |
String from = "[email protected]"; | |
String host = "localhost"; | |
// Get system properties | |
Properties properties = System.getProperties(); | |
// Setup mail server | |
properties.setProperty("mail.smtp.host", host); | |
// Get the default Session object. | |
Session session = Session.getDefaultInstance(properties); | |
try{ | |
// Create a default MimeMessage object. | |
MimeMessage message = new MimeMessage(session); | |
// Set From: header field of the header. | |
message.setFrom(new InternetAddress(from)); | |
// Set To: header field of the header. | |
message.addRecipient(Message.RecipientType.TO, | |
new InternetAddress(to)); | |
// Set Subject: header field | |
message.setSubject("This is the Subject Line!"); | |
// Now set the actual message | |
message.setText(content); | |
// Send message | |
Transport.send(message); | |
System.out.println("Sent message successfully...."); | |
}catch (MessagingException mex) { | |
mex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment