Note that there are some explanatory texts on larger screens.

plurals
  1. POMessagingException thrown on some machines, but on others it works fine
    primarykey
    data
    text
    <p>I'm trying to write a method that sends an email based on parameters, and it works completely on CentOS and OSX. However, the method doesn't work properly on Windows (even when recompiled on Windows) as well as some other Linux OS's - it throws a MessagingException. Does anyone have any ideas as to how I can fix this to work on Windows? Thanks!</p> <pre><code>private static void sendEmail(String towhom, String subject, String body) { String host = "smtp.gmail.com", from = "myemail", pass = "mypassword"; Properties props = System.getProperties(); Scanner scan = new Scanner(System.in); try { props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); InternetAddress toAddress = new InternetAddress(towhom); message.addRecipient(Message.RecipientType.TO, toAddress); message.setSubject(subject); message.setText(body); Transport transport = session.getTransport("smtp"); transport.connect(host, from, pass); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch(AddressException e) { System.out.println("Invalid Email Address."); } catch(MessagingException e) { System.out.print("\nInvalid Email Address, please reenter it: "); sendEmail(scan.nextLine(), subject, body); } } </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.
 

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