Java Mail

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailClass {

public static void main(String[] args) throws Exception {

Properties props = new Properties();
props.put(“mail.host”, “mail.dwp.com”);

Session mailConnection = Session.getInstance(props, null);
Message msg = new MimeMessage(mailConnection);

Address a = new InternetAddress(“vishal2000@a.com”, “Vishal Kumar”);
Address b = new InternetAddress(“kamal_ss@java2s.com”,”kamal sharn”);

msg.setContent(“Mail contect”, “text/plain”);
msg.setFrom(a);
msg.setRecipient(Message.RecipientType.TO, b);
msg.setSubject(“subject”);

Transport.send(msg);
}
}

Leave a Comment