AnsweredAssumed Answered

How to send an Email from a B2?

Question asked by cb0044138 on Jan 15, 2016
Latest reply on Oct 25, 2017 by tv0069020

Hi guys, I'm trying to send an email when an exception happens, my code is as follows:

 

Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
     System.out.println("Sending Email.....");

     Message msg = new MimeMessage(session);

     msg.setFrom(new InternetAddress("no-reply@blackboard.com", "AIEP Admin"));

     msg.addRecipient(Message.RecipientType.TO, new InternetAddress("cesar.bonilla@laureate.net", "Cesar Bonilla"));

     msg.setSubject("ERROR EN CARPETA ELECTRONICA DOCENTE");

     msg.setText(emailBody);

     Transport.send(msg);

} catch (UnsupportedEncodingException e1) {

     e1.printStackTrace();

} catch (MessagingException e1) {

      e1.printStackTrace();

}

 

I'm not really sure what I'm doing wrong, but I get this error:

 

INFO   | jvm 1| 2016/01/15 16:43:42 | Sending Email.....
INFO   | jvm 1| 2016/01/15 16:43:42 | javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
INFO   | jvm 1| 2016/01/15 16:43:42 |   nested exception is:
INFO   | jvm 1| 2016/01/15 16:43:42 |     java.net.ConnectException: Connection refused

 

Any advice would be apreciated .

Outcomes