Cannot send email in designer using SimpleMailSender API
Cannot send email in designer using SimpleMailSender API
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:
<code>
SimpleMailSender mailSender = new SimpleMailSender(attachmentFiles, emailConfig, Ivy.log());
mailSender.sendMessage();
</code>
But I got an exception with content:
<pre>
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
</pre>
I think the problem is that API SimpleMailSender.sendMessage() uses **port 25** which is cannot be accessed to connect to SMTP server: **Couldn't connect to host, port: localhost, 25; timeout -1**.
I also tested email sending function with UI and could send email successfully:
![alt text][1]
[1]: https://answers.axonivy.com/upfiles/Capture_6KER93W.PNG
You see, it's using port **2525**. If I change port to **25**, I cannot send email.
So how can I config the port when sending the email with ivy API?
Thank you