#1 2020-09-28 15:43:00

DISSTeam
Member
Registered: 2020-09-11

Exchange 365 Mail Relay

Has anyone successfully got exchange 365 set up on their report server -as a mail relay for the email system?

I've set up my config file properly - I am not authenticating as I don't need it. Set up my exchange connector with the IP of the report server. I've done everything, in fact I've done it twice! And it just will not send mail.

DOes anyone else have an issue?

I'm using the latest Bitnami build.

Offline

#2 2020-09-28 18:20:12

DISSTeam
Member
Registered: 2020-09-11

Re: Exchange 365 Mail Relay

So further testing - I got the system to work routing through the same port but a different SMTP relay service. Just not exchange 365...interesting - I;ll keep playing.

Offline

#3 2020-09-29 06:37:57

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Exchange 365 Mail Relay

Hi DISSTeam,

pls check here for our settings in our Exchange 365 test server:

https://forum.reportserver.net/viewtopi … 7532#p7532

Regards,
Eduardo

Offline

#4 2020-09-29 08:38:32

DISSTeam
Member
Registered: 2020-09-11

Re: Exchange 365 Mail Relay

Thanks

I have used your example too.

Caused by: javax.mail.MessagingException: Could not connect to SMTP host: ******.mail.protection.outlook.com, port: 587;
  nested exception is:
    java.net.ConnectException: Connection timed out (Connection timed out)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
        at javax.mail.Service.connect(Service.java:317)
        at javax.mail.Service.connect(Service.java:176)
        at javax.mail.Service.connect(Service.java:125)
        at javax.mail.Transport.send0(Transport.java:194)
        at javax.mail.Transport.send(Transport.java:124)
        at net.datenwerke.rs.core.service.mail.MailServiceImpl.sendMailSync(MailServiceImpl.java:237)
        ... 4 more

I've also tried smtp.outlook.com

The same error above.

I've opened all firewall rules so it doesn't appear to be that.

And it works fine port 587 with a third party SMTP relay provider.

Offline

#5 2020-09-29 11:58:27

DISSTeam
Member
Registered: 2020-09-11

Re: Exchange 365 Mail Relay

To confirm, my set up is - and I do not authenticate.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <smtp>
      <host>***.mail.protection.outlook.com</host>
      <port>587</port>
      <ssl>false</ssl>
      <tls>
         <enable>true</enable>
         <require>false</require>
      </tls>
   </smtp>
   <mail>
      <sender>email@domain.com</sender>
      <senderName>DISSTeam</senderName>
      <forceSender>false</forceSender>
      <encryptionPolicy>allow_mixed</encryptionPolicy>
   </mail>
</configuration>

Last edited by DISSTeam (2020-09-29 11:58:57)

Offline

#6 2020-09-29 14:40:42

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Exchange 365 Mail Relay

Hi DISSTeam,

DISSTeam wrote:

and I do not authenticate.

you don't authenticate ? I don't quite understand this. How does the server authenticate the user then?

Anyhow, could you try this groovy script:

import java.util.Properties
import javax.mail.Authenticator
import javax.mail.Message
import javax.mail.PasswordAuthentication
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage

final def TO = "to"
final def FROM = "from"
final def SUBJECT = "subject"
final def SMPTPHOST = "host"
final def SMPTPORT = "port"
final def USERNAME = "username"
final def PASS = "your_password"
  

new SendMail().test(TO, FROM, SUBJECT, SMPTPHOST, SMPTPORT, USERNAME, PASS)

public class SendMail {
    public void test(String to, String from, String subject, String smtpHost, String smtpPort, String username, String password) throws Exception {
        def props = new Properties()
        props.put("mail.transport.protocol", "smtp")
        props.put("mail.smtp.host", smtpHost)
        props.put("mail.smtp.port", smtpPort)
        props.put("mail.smtp.auth", "true")
 
        def auth = new SMTPAuthenticator(username, password)
        def mailSession = Session.getInstance (props, auth)
        // uncomment for debugging infos to stdout
        mailSession.setDebug(true)
        def transport = mailSession.getTransport()
 
        def message = new MimeMessage(mailSession)
        message.setSubject(subject)
        message.setContent("My text", "text/plain")
        message.setFrom(new InternetAddress(from))
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to))
 
        transport.connect();
        transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO))
        transport.close()
    }
 
    private class SMTPAuthenticator extends javax.mail.Authenticator {
        private String username
        private String password
 
        public SMTPAuthenticator(String username, String password) {
            this.username = username
            this.password = password
        }
 
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password)
        }
    }
}

It just sends a test email. Here, we have simple authentication options, which may give us a hint why this is not working in your case.
ReportServer sends emails in a similar way, so this abstracts other ReportServer configuration away.

You may also try these settings in the props:

props.put("mail.smtp.starttls.enable","true");

and / or this :

// enable authentication
props.put("mail.smtp.starttls.enable","true");
           
// SSL Factory
props.put("mail.smtp.socketFactory.class",
      "javax.net.ssl.SSLSocketFactory");

Regards,
Eduardo

Offline

#7 2020-09-29 15:26:37

DISSTeam
Member
Registered: 2020-09-11

Re: Exchange 365 Mail Relay

Well no, we don't authenticate as we send from an alias not from a genuine mail account. We do this with our webserver just fine and E365 has the appropriate connector set up to allow this and the SPF records are adjusted accordingly.

I am sensing though through my trials that relaying through Exchange 365 requires SMTP auth regardless when being sent in this way.

Offline

#8 2020-09-30 08:26:38

DISSTeam
Member
Registered: 2020-09-11

Re: Exchange 365 Mail Relay

I think an issue may be TLS. When enabled it doesn't seem to connect properly to any SMTP relay service. More testing needed but as it's a standard Bitnami Azure setup - I don't suppose I need any further changes to the server to get this to work as standard.
Mail relay service supports TLS

Offline

#9 2020-09-30 08:52:11

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Exchange 365 Mail Relay

Hi DISSTeam,

did you test the script I sent with tls enabled?
what output do you get in the logs ?

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB