Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was driving me crazy and so just wanted to add what worked for me. I had to update my version of JavaMail (1.4.5) for this to work - not sure what version was being used before.</p> <p>Once I updated to new version of JavaMail, the following code worked for me (can uncomment the debug lines to get additional debugging info - port was <code>587</code> and host was <code>smtp.gmail.com</code>):</p> <pre><code>public void sendMailWithAuth(String host, String user, String password, String port, List&lt;String&gt; toList, String htmlBody, String subject) throws Exception { Properties props = System.getProperties(); props.put("mail.smtp.user",user); props.put("mail.smtp.password", password); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); //props.put("mail.debug", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.EnableSSL.enable","true"); Session session = Session.getInstance(props, null); //session.setDebug(true); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(user)); // To get the array of addresses for (String to: toList) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); } message.setSubject(subject); message.setContent(htmlBody, "text/html"); Transport transport = session.getTransport("smtp"); try { transport.connect(host, user, password); transport.sendMessage(message, message.getAllRecipients()); } finally { transport.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload