Java Reference
In-Depth Information
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:
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 =
private final String userPassword =
private Session session;
public MailSender() {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
Search WWH ::

Custom Search