<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Cannot send email in designer using SimpleMailSender API</title><link>https://answers.axonivy.com/questions/3262/cannot-send-email-in-designer-using-simplemailsender-api</link><description>&lt;p&gt;Hi, I'm trying to use ivy API to send mail in my Designer (v7.1.0.58009). I send an email with code snippet like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
SimpleMailSender mailSender = new SimpleMailSender(attachmentFiles, emailConfig, Ivy.log());
mailSender.sendMessage();
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But I got an exception with content:
&lt;/p&gt;&lt;pre&gt;Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712)
    at javax.mail.Service.connect(Service.java:366)
    at javax.mail.Service.connect(Service.java:246)
    at javax.mail.Service.connect(Service.java:195)
    at javax.mail.Transport.send0(Transport.java:254)
    at javax.mail.Transport.send(Transport.java:124)
    at ch.ivyteam.ivy.email.internal.SendMail.doSendMessage(SendMail.java:136)
    at ch.ivyteam.util.callable.AbstractExecutionContext.lambda$0(AbstractExecutionContext.java:28)
    at ch.ivyteam.util.callable.AbstractExecutionContext.callInContext(AbstractExecutionContext.java:16)
    at ch.ivyteam.util.callable.AbstractExecutionContext.executeInContext(AbstractExecutionContext.java:26)
    at ch.ivyteam.ivy.email.internal.SendMail.sendMessage(SendMail.java:115)
    at ch.ivyteam.ivy.email.SimpleMailSender.sendMessage(SimpleMailSender.java:94)
    at ch.ivy.gawfs.mail.Mail.lambda$0(Mail.java:29)
    at ch.ivyteam.util.callable.AbstractExecutionContext.callInContext(AbstractExecutionContext.java:16)
    at ch.ivyteam.ivy.security.internal.SecurityManager.executeAsSystem(SecurityManager.java:1128)
    at ch.ivy.addon.portalkit.util.IvyExecutor.executeAsSystem(IvyExecutor.java:14)
    ... 123 more
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I think the problem is that API SimpleMailSender.sendMessage() uses &lt;strong&gt;port 25&lt;/strong&gt; which is cannot be accessed to connect to SMTP server: &lt;strong&gt;Couldn't connect to host, port: localhost, 25; timeout -1&lt;/strong&gt;.
I also tested email sending function with UI and could send email successfully:
&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/Capture_6KER93W.PNG"&gt;&lt;/p&gt;
&lt;p&gt;You see, it's using port &lt;strong&gt;2525&lt;/strong&gt;. If I change port to &lt;strong&gt;25&lt;/strong&gt;, I cannot send email.
So how can I config the port when sending the email with ivy API?
Thank you&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3262/cannot-send-email-in-designer-using-simplemailsender-api" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 10 May 2018 14:49:29 -0400</lastBuildDate><item><title>Answer by Alex Suter</title><link>https://answers.axonivy.com/questions/3262/cannot-send-email-in-designer-using-simplemailsender-api/3264</link><description>&lt;p&gt;&lt;code&gt;SimpleMailSender&lt;/code&gt; is not a public api. I don't recommend to use that directly, because there is a lot of special stuff done in ivy. E.g. port handling in the designer.&lt;/p&gt;
&lt;p&gt;I made a sample on GitHub: &lt;a href="https://github.com/ivy-samples/mail-over-java-api-sample"&gt;https://github.com/ivy-samples/mail-over-java-api-sample&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this sample I show you how you could wrap the Mail Activity in a Sub Process with an own Java API. Because for now the most proper way to send mail in ivy is still over the mail step. You won't have any curious problems. In future - ivy should provide an java api to send mail (e.g. &lt;code&gt;ivy.mail&lt;/code&gt;).&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Thu, 10 May 2018 14:49:29 -0400</pubDate><guid>https://answers.axonivy.com/questions/3262/cannot-send-email-in-designer-using-simplemailsender-api/3264</guid></item></channel></rss>