Java Reference
In-Depth Information
InternetAddress("malindaped@yahoo.fr");
msg.setRecipients(Message.RecipientType.TO,internetAddresses);
msg.setSubject("Pre-inscription results");
msg.setText("Dear Malinda, we inform you
that …");
3. Send the message. We send a message in one line with the Transport
class. The following code shows how to send the message:
Transport.send(msg);
The following code shows how to send the results of preregistration for individual
candidates from a Gmail account. As you can see, the Gmail sender account and
its password are passed as a parameter to the send method. This allows the ap-
plication to be authenticated by the server when sending the message. To test the
sending code associated with this chapter, you need to have a Gmail account and
replace username with the username of your account and user_password with
the password of this account.
The following code is an example of sending an e-mail via Gmail SMTP server by
using JavaMail API:
public class MailSender {
private final String userName =
"username@gmail.com";
private final String userPassword =
"user_password";
private Session session;
public MailSender() {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable",
"true");
props.put("mail.smtp.host",
"smtp.gmail.com");
Search WWH ::




Custom Search