Relay SMTP messages to Office 365 / Smart Host

infocenter

Member
Feb 28, 2014
6
3
3
cPanel Access Level
Reseller Owner
I can assure you that I have investigated this topic for hours before posting here. So here is so far what I have found:

Set up connectors to route mail between Office 365 and your own email servers

The office365 to our VPS connector is setup properly and we get emails to our VPS (on our WHM/cPanel).

We are now trying to setup the smart host so all the emails are routed / relayed to microsoft office 365 and then is sent through them. We have also created the inbound connectors per Microsoft suggestion (above link)

We tried Exim Configuration Manager>>Smarthost support>>

and we used *.protection.outlook.com or *.office365.com

nothing worked and our emails are bounced when we try to send emails from our VPS (cPanel).

Is there anyone who has successfully setup a connector for Micorosoft 365 and split the emails between exchange and WHM?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @infocenter,

Can you let us know the specific bounce message that you receive? Also, can you check if Local Mail Exchanger is configured for the domain you are testing with in cPanel >> Email Routing?

Also, while the setup is different to yours, you may find some of the discussion in the following thread helpful:

Using cPanel and Office 365 in a hybrid scenario

Thank you.
 

infocenter

Member
Feb 28, 2014
6
3
3
cPanel Access Level
Reseller Owner
Email routing is set to "Automatic - Local" the bounce email message is as follows. The discussion you suggested goes back to 2011! Office 365 has changed a lot since then. However we have followed what has been suggested on the discussion. As mentioned we don't have any issue receiving emails. But we have the problem of sending out emails when Smart Host option is set.

_________________________________________________________
Code:
Return-Path: <>
Delivered-To: [email protected]
Received: from myhostname.com
        by myhostname.com with LMTP id oHBLF2IzmFuMaQAAVoenzA
        for <[email protected]>; Tue, 11 Sep 2018 16:28:02 -0500
Return-path: <>
Envelope-to: [email protected]
Delivery-date: Tue, 11 Sep 2018 16:28:02 -0500
Received: from mailnull by myhostname.com with local (Exim 4.91)
        id 1fzqCY-00071d-Ah
        for [email protected]; Tue, 11 Sep 2018 16:28:02 -0500
X-Failed-Recipients: [email protected]
Auto-Submitted: auto-replied
From: Mail Delivery System <[email protected]>
To: [email protected]
Content-Type: multipart/report; report-type=delivery-status; boundary=1536701282-eximdsn-780460104
MIME-Version: 1.0
Subject: Mail delivery failed: returning message to sender
Message-Id: <[email protected]>
Date: Tue, 11 Sep 2018 16:28:02 -0500
--1536701282-eximdsn-780460104
Content-type: text/plain; charset=us-ascii
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
  [email protected]
    The mail server could not deliver mail to
OLE_LINK13">[email protected]  The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.
--1536701282-eximdsn-780460104
Content-type: message/delivery-status
Reporting-MTA: dns; myhostname.com
Action: failed
Final-Recipient: rfc822;[email protected]
Status: 5.0.0
--1536701282-eximdsn-780460104
Content-type: message/rfc822
Return-path: <[email protected]>
Received: from [::1] (port=58240 helo=myhostname.com)
        by myhostname.com with esmtpa (Exim 4.91)
        (envelope-from <[email protected]>)
        id 1fzqCY-00070Z-72
        for [email protected]; Tue, 11 Sep 2018 16:28:02 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII;
format=flowed
Content-Transfer-Encoding: 7bit
Date: Tue, 11 Sep 2018 16:28:02 -0500
From: [email protected]
To: [email protected]
Subject: Testing Emails
Message-ID: <[email protected]>
X-Sender: [email protected]
User-Agent: Roundcube Webmail/1.3.3
Test Message
--1536701282-eximdsn-780460104--
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @infocenter,

Can you also let us know the output from /var/log/exim_mainlog when sending a message? EX:

Code:
exigrep SUBJECT /var/log/exim_mainlog
Additionally, have you tested sending out email to other remote destinations aside from Gmail?

Thank you.
 

infocenter

Member
Feb 28, 2014
6
3
3
cPanel Access Level
Reseller Owner
Here is the log. Also we tried other email addresses like those on Microsoft , Yahoo, and others and the email bounces immediately. Per Microsoft Smart Host should be set to smtp.office365.com
Code:
[[email protected] without main domain ~]# exigrep OutgoingcPanelTest1 /var/log/exim_mainlog2018-09-12 21:09:22 1g0H4M-0008Mb-CE <= [email protected] H=(Hostname) [::1]:48430 P=esmtpa A=dovecot_login:[email protected] S=645 [email protected] T="OutgoingcPanelTest1" for [email protected]

2018-09-12 21:09:22 1g0H4M-0008Mb-CE Sender identification U=mydomain D=mydomain.com [email protected] 21:09:22 1g0H4M-0008Mb-CE SMTP connection outbound 1536804562 1g0H4M-0008Mb-CE mydomain.com [email protected]

2018-09-12 21:09:22 1g0H4M-0008Mb-CE ** [email protected] R=fail_remote_domains: The mail server could not deliver mail to [email protected] The account or domain may not exist, they may be blacklisted, or missing the proper dns entries.

2018-09-12 21:09:22 1g0H4M-0008Mb-CE Completed
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @infocenter,

Could you open a support ticket so we can take a closer look and see if there's anything obvious in your configuration that's causing this problem? You can post the ticket number here and we'll link this thread to the ticket.

Thank you.
 

infocenter

Member
Feb 28, 2014
6
3
3
cPanel Access Level
Reseller Owner
So the issue is resolved (almost-read the notes below). For those of you who might be interested this is how it got resolved (thanks cPanel Support :) )

Step 1)
Email Routing is set to "Local"

Step 2) Go to your Microsoft Office 365 Admin portal and setup your connectors ( See this: Set up connectors to route mail between Office 365 and your own email servers)

Note: For the Inbound Connector you should use your VPS IP address. We tried using the domain but it didn't work. So use the VPS IP address. Just remember; that needs to be a dedicated IP (per their instructions).

Step 3) Go to your WHM>> Exim Configuration Manager>>Mail>>Smarthost Support

Change the setting of Smarthost Support to * mydomain-com.mail.protection.outlook.com


Some notes:

A) Consider the * and space between * and the domain. That was the issue we had so make sure to use * yourdomain-com.mail.protection.outlook.com

B) Remember it's not a dot between yourdomain and com. It's a dash line. yourdomain-com not "yourdomain.com"

C) We rebooted our whole VPS once even though rebooting Exim should be enough but it worked after full VPS reboot.

I hope this post helps other.

Just FYI Final Note:

This solutions is not perfect. Here is the issue.

Scenario: mydomain1.com and mydomain2.com are hosted both on the same VPS. For both domains some emails are hosted locally (on VPS) and some on Microsoft Exchange. For example, [email protected] resides on VPS but [email protected] is on Microsoft Exchange. But because the email routing is set to Local (remember Step 2? It won't work if you don't set it to local) then VPS just tries to send the emails to local which means it only tries to send the email only to local so if that user doesn't exist on the VPS but on microsoft exchange you will receive a bounced email. We are working on a solution for that but at least this is a temporary solution for the above issue.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @infocenter,

Thanks for sharing! We'll look forward to seeing what you find regarding the per-email account configuration. Note that we have had some threads about that in the past, but I'm not sure it would help in your particular scenario. Here's the link if you're interested:

Routing email to external server using EXIM smarthost config.

Thank you.