Java Reference
In-Depth Information
= Session.getDefaultInstance(properties, new
MessageAuthenticator("username","password"));
Message message = new MimeMessage(session);
try {
message.setFrom(new
InternetAddress("someone@somewhere.com"));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress("someone@somewhere.com"));
message.setSubject("Subject");
message.setContent("This is a test message",
"text/plain");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
class MessageAuthenticator extends Authenticator {
PasswordAuthentication authentication = null;
public MessageAuthenticator(String username, String
password) {
authentication = new
PasswordAuthentication(username,password);
}
@Override
protected PasswordAuthentication
getPasswordAuthentication() {
return authentication;
}
}
How It Works
To utilize the JavaMail API, start by creating a Properties object that works as a
standard Map object (in fact, it inherits from it), in which you put the different proper-
Search WWH ::




Custom Search