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:

SimpleMailSender mailSender = new SimpleMailSender(attachmentFiles, emailConfig, Ivy.log()); mailSender.sendMessage();

But I got an exception with content:

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

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

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

asked 10.05 at 00:29

nguyen_to's gravatar image

nguyen_to
114
accept rate: 0%

edited 10.05 at 00:29


SimpleMailSender 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.

I made a sample on GitHub: https://github.com/ivy-samples/mail-over-java-api-sample

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. ivy.mail).

link

answered 10.05 at 14:49

Alex%20Suter's gravatar image

Alex Suter ♦♦
1.7k61634
accept rate: 83%

edited 11.05 at 01:57

Hi @Alex Suter, can I send multi attachments using E-Mail step of ivy. I see that in tab Attachments of E-Mail step, I can only put one attachment file by one attachment row. Assume that I have a dynamic attachment files: Map< String, File > in.attachedFiles, how can I attach that map to email.

(11.05 at 03:56) nguyen_to nguyen_to's gravatar image

@Alex Suter, as I understand from the link you provided, the solution can be applied if we already known the number of attachments. But my situation has a difference, that is the number of attachments is dynamic, they are a list of files from a java variable!

(11.05 at 10:09) nguyen_to nguyen_to's gravatar image

Yes. You could fill up your generic mail step with 100 of these entries. I assume nobody sends email with 100 entries.

(11.05 at 10:23) Alex Suter ♦♦ Alex%20Suter's gravatar image

Hello @Alex Suter, one more question, I got error in log when trying to attach file: IllegalArgumentException: File could not be found! C:\work\designer7.1.0.58009_Windows_x64\files\application\testFile.txt. But I'm sure this file with this path exists! Do you know what is the problem here. Thank you!

(14.05 at 06:49) nguyen_to nguyen_to's gravatar image

I got the reason, because I used wrong File api (java.io.File)

(14.05 at 07:30) nguyen_to nguyen_to's gravatar image
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×62
×25

Asked: 10.05 at 00:29

Seen: 125 times

Last updated: 14.05 at 07:32