Skip to content

Instantly share code, notes, and snippets.

@madan712
Created January 10, 2013 13:10
Show Gist options
  • Save madan712/4501951 to your computer and use it in GitHub Desktop.
Save madan712/4501951 to your computer and use it in GitHub Desktop.
Simple java program to send Mail using JavaMail API
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();
}
}
}
@anujtiwari05
Copy link

authentication exception coming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment