Created
January 10, 2013 13:10
-
-
Save madan712/4501951 to your computer and use it in GitHub Desktop.
Simple java program to send Mail using JavaMail API
This file contains hidden or 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
import java.util.Properties; | |
import javax.mail.Message; | |
import javax.mail.Session; | |
import javax.mail.Transport; | |
import javax.mail.internet.InternetAddress; | |
import javax.mail.internet.MimeMessage; | |
public class JavaMail { | |
public static void main(String[] args) { | |
Properties props = new Properties(); | |
props.put("mail.smtp.host", "host.javaxp.com"); | |
try { | |
Session session = Session.getDefaultInstance(props, null); | |
session.setDebug(true); | |
MimeMessage msg = new MimeMessage(session); | |
msg.setSubject("Test Mail"); | |
msg.setText("This is an automated mail genrated by System.\nThanks,\nJavaXp.com"); | |
msg.setFrom(new InternetAddress("[email protected]")); | |
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]")); | |
msg.addRecipient(Message.RecipientType.CC, new InternetAddress("[email protected]")); | |
msg.saveChanges(); | |
Transport transport = session.getTransport("smtp"); | |
transport.connect(); | |
transport.sendMessage(msg, msg.getAllRecipients()); | |
transport.close(); | |
} catch (Exception ex) { | |
System.out.println("Exception occured"); | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
authentication exception coming