Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Unable to send email from AEMCaas

Avatar

Level 3

Dear folks ,

We are using default mail service to send emails but we are facing issue to send emails. We have used below OSGI configuration and from local system we can send email but not from AEM cloud.
OSGI Config :

{
"smtp.host": "$[env:AEM_PROXY_HOST;default=proxy.tunnel]",
"smtp.port": "30587",
"smtp.user": "$[env:EMAIL_USERNAME;default=1ec6dcbd9bf44864a6d506ae22d48026]",
"smtp.password": "$[secret:EMAIL_PASSWORD]",
"from.address": "abcd@xyz.com",
"smtp.starttls": true,
"smtp.requiretls": false,
"debug.email": false,
"oauth.flow": false
}


ERROR :

Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : proxy.tunnel:30587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469) [org.apache.commons.email:1.5.0]
at org.apache.commons.mail.Email.send(Email.java:1496) [org.apache.commons.email:1.5.0]
at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:331) [com.day.cq.cq-mailer:5.4.22]
... 160 common frames omitted
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: proxy.tunnel, 30587; timeout 60000
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209) [com.sun.mail.javax.mail:1.6.2]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740) [com.sun.mail.javax.mail:1.6.2]
at javax.mail.Service.connect(Service.java:388) [com.sun.mail.javax.mail:1.6.2]
at javax.mail.Service.connect(Service.java:246) [com.sun.mail.javax.mail:1.6.2]
at javax.mail.Service.connect(Service.java:195) [com.sun.mail.javax.mail:1.6.2]
at javax.mail.Transport.send0(Transport.java:254) [com.sun.mail.javax.mail:1.6.2]
at javax.mail.Transport.send(Transport.java:124) [com.sun.mail.javax.mail:1.6.2]
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459) [org.apache.commons.email:1.5.0]
... 162 common frames omitted
Caused by: java.net.UnknownHostException: proxy.tunnel

NOTE : We are using outlook as email service provider and we came to know from document that port 587 need to be enabled but not sure about that.
Any suggestion from anyone will be of great help to us.

Kind Regards,
Kaushik Datta

1 Accepted Solution

Avatar

Correct answer by
Level 3

@vivmishr we have defined in below manner , the problem was due to dedicated egress IP address was not whitelisted from Outlook server end . After whitelisting it worked well.

{
"smtp.host": "$[env:AEM_PROXY_HOST;default=proxy.tunnel]",
"smtp.port": 30587,
"smtp.user": "$[env:EMAIL_USERNAME]",
"smtp.password": "$[secret:EMAIL_PASSWORD]",
"from.address": "xxxx@xxxx.com",
"smtp.ssl": false,
"smtp.starttls": true,
"smtp.requiretls":true
}

 Thanks all of you for support.

View solution in original post

6 Replies

Avatar

Community Advisor

@kdatta I tried below config and it worked for me in AEMaaCS

{
"debug.email": false,
"smtp.user": "$[secret:smtpuser]",
"smtp.password": "$[secret:smtppassword]",
"smtp.port": 465,
"smtp.ssl": true,
"smtp.starttls": true,
"smtp.host": "in.mailjet.com",
"from.address": "noreply@domain.com"
}

Their is a flexiablity in AEMaaCS that you can configure the smtp username and password from the environment variable as well  

Avatar

Level 3

Hi @Jagadeesh_Prakash ,

I tried with same config only as mentioned by you , only difference is 

smtp.ssl = false

as I am using outlook server . The problem was with port , by default 587 port is disabled , we need to enable that using advance networking.
 

Avatar

Employee

@Jagadeesh_Prakash This is bad practise- you should not define host directly in config file in AEMaaCS. Rather use proxy.tunnel i.e. $[env:AEM_PROXY_HOST;default=proxy.tunnel]. Looks like you are not following the link you posted. 

 

Anyone looking at this thread, please refer this blog post to enable flexible port egress: [0]. Also enable "debug.email": true in your DefaultMailService configuration. Once this is done- you can look at error logs to find out issue with email sending. In my case I saw this error:

"Caused by: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message"

So Disabled ssl like this- "smtp.ssl": false. It resolved the issue.

[0]- https://aem6solutions.blogspot.com/2023/04/enable-smtp-host-and-port-in-aem-cloud.html 

[1]- https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/networking/examples/e...

Avatar

Correct answer by
Level 3

@vivmishr we have defined in below manner , the problem was due to dedicated egress IP address was not whitelisted from Outlook server end . After whitelisting it worked well.

{
"smtp.host": "$[env:AEM_PROXY_HOST;default=proxy.tunnel]",
"smtp.port": 30587,
"smtp.user": "$[env:EMAIL_USERNAME]",
"smtp.password": "$[secret:EMAIL_PASSWORD]",
"from.address": "xxxx@xxxx.com",
"smtp.ssl": false,
"smtp.starttls": true,
"smtp.requiretls":true
}

 Thanks all of you for support.

Avatar

Employee

Yes, this is what the configuration format should be. Thank you for confirmation that this works. We should not put actual host and port in this config.