Sending emails from scripts via Office 365

I have several scripts that were working for our on-prem exchange. Now that we have moved out to 365 obviously the SMTP gateway has moved, but after trying to get these working again today I cannot make it work.

I found the article How to set up a multifunction device or application to send email using Office 365

It looks good, but I found my IP blocked, and so delisted it via https://sender.office.com

(PII moved to Private Message by moderator)

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

Hi Rhys, 

 

Thank you for your post. I would like to ask the detailed steps on how you use the script for your On-Premises exchange.

 

Have you recent done a migration from Office 365?

 

As an admin go to Exchange Admin Center(EAC), and try to delist the user. Here is the link https://technet.microsoft.com/en-us/library/dn458545(v=exchg.150).aspx. Please involve your admin if you are not a member of the Office 365 admin in your organization. 

Looking forward to your updates.

 

Best Regards,

Ruel

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thanks for the reply Ruel:

 I would like to ask the detailed steps on how you use the script for your On-Premises exchange.

We do not have an on-prem exchange anymore - we moved to 365, hence I altered the scripts for 365 (without success).

Sadly a moderator has removed the scripts and results I posted despite the fact I had annonymised all references to our domain, email addresses and smtp uri etc .

Have you recent done a migration from Office 365?

We recently migrated to 365.

As an admin go to Exchange Admin Center(EAC), and try to delist the user.

Thanks for the link - there are no blocked addresses in EAC>Protection>Action Center

I still get the same error:

Send-MailMessage : Mailbox unavailable. The server response was: 5.7.51 TenantInboundAttribution; There is a partner connector configured that matched the message's recipient domain. The connector had either the 
RestrictDomainsToIPAddresses or RestrictDomainsToCertificate set [XXXXXXXXXXXX.eop-AUS01.prod.protection.outlook.com]

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Rhys,

Thanks for your clarification. 

Since you are using Office 365 (online, no Exchange on-premises), may I know the detailed symptom about the issue (the error you got)? I mean, you have mentioned Office 365 smtp relay (https://support.office.com/en-us/article/How-to-set-up-a-multifunction-device-or-application-to-send-email-using-Office-365-69f58e99-c550-4274-ad18-c805d654b4c4?ui=en-US&rs=en-AU&ad=AU#option3). And, according to the error message “There is a partner connector configured that matched the message's recipient domain”, my understanding is that you were using the third method “Configure a connector to send mail using Office 365 SMTP relay” described in that article. 

If so, please be noted that this method is to authenticate your device to relay the email to Office 365 and then relay to the recipient. That is to say, it used Office 365 (online) smtp server “smtp.office365.com”. Besides, it needs a static IP address or IP range as well as 25 port. The detailed requirement of this method can be found “Requirement for Office 365 SMTP relay” or that article. 

If all the requirements have been met but the issue persists, I’d like to collect the complete NDR (Non-Delivery Report) in the private message for analysis and a screenshot of the device settings (Configure a connector to send mail using Office 365 SMTP relay). By the way, why you don’t send from your Office 365 mailbox to the recipient directly?

Regards,
-----------------------

* Beware of scammers posting fake support numbers here.

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Arrrghhhh!!!!

While it is great to have many people looking to resolve this issue, when the different people do not work in concert it actually makes this harder and produces worse results than ignoring the issue.

I have annonymised all the scripts and results I have posted. Please do not remove as they are likely important to understanding the issue.

  • I am in an environment without an exchange - we use exchange online.
  • I am following mehtod 2 (direct send) as described in the article:
    How to set up a multifunction device or APPLICATION to send email using Office 365
  • There are no blocked addresses in EAC>Protection>Action Center.
  • I do not get an NDR, because the mail is never accepted by the exchange to be sent.
  • I do not send the message directly from my mailbox because the email is generated by a script.
    The purpose of each scripts is to automate a task and report on it.

******************* PLEASE DO NOT REMOVE ANY INFORMATION *******************

********** THE INFORMATION BELOW DOES NOT CONTAIN PRIVATE DATA **********

Both VB and PowerShell scripts give:

Send-MailMessage : Mailbox unavailable. The server response was: 5.7.51 TenantInboundAttribution; There is a partner connector configured that matched the message's recipient domain. The connector had either the RestrictDomainsToIPAddresses or RestrictDomainsToCertificate set [XXXXXXXXXXXXXXXX.prod.protection.outlook.com]

NB I am guessing with VB because it doesn't quite all fit in the dialog box.

If you need to see the scripts the relevant parts are:

PowerShell

Send-MailMessage -From *** Email address is removed for privacy *** -Subject **Subject** -To *** Email address is removed for privacy *** -Attachments **Attachment\path -Body **Body** -SmtpServer my-365-domain-com-au.mail.protection.outlook.com

NB same result when I send from my address to my address via this method

VBS

strSMTPFrom = "*** Email address is removed for privacy ***"
strSMTPTo = "*** Email address is removed for privacy ***"
strSMTPRelay = "my-365-domain-com-au.mail.protection.outlook.com"
strTextBody = "**BODY**"
strSubject = "**SUBJECT**"
'strAttachment = "full UNC path of file"

Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
oMessage.Configuration.Fields.Update

oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment

oMessage.Send
Wscript.Echo "Message sent regarding:"& chr(13) & strSubject


2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Rhys,

To conclude your question, I find the issue you encounter is that you can send emails via the Powershell and VB Script you provide above before your account migrated from Exchange on-premise to Exchange Online. And you send emails between users in same Office 365 organization via Direct Send.

But you cannot send emails now using same Powershell and Scripts.

The symptom about you cannot send emails is that there will be an error occurs like: Send-MailMessage : Mailbox unavailable. The server response was: 5.7.51…

If yes,  from the error report, I find that the error might be caused by the sender has no permission to send emails, I would like to confirm the following information for troubleshooting:

1. Are you send emails via Send As permission?

2. The detailed email addresses of the sender and recipient.

In order to protect your privacy, please send us the email addresses of sender and recipient via private message.

Please let me know  if there is any misunderstanding.

Thanks,

Amanda

[Updated by Amanda Zhang MSFT, 5:21am , may 2017 (UTC)]

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Amanda,

I find the issue you encounter is that you can send emails via the Powershell and VB Script you provide above before your account migrated from Exchange on-premise to Exchange Online. 

Incorrect. The scripts above refer to Office 365 SMTP servers. Please ignore hte fact that these ever worked or that we migrated. I want these scripts to send email via Office 365 SMTP servers.

And you send emails between users in same Office 365 organization via Direct Send.

No. I cannot send via direct send - that is why I have made my post.

The symptom about you cannot send emails is that there will be an error occurs like: Send-MailMessage : Mailbox unavailable. The server response was: 5.7.51…

Correct

If yes,  from the error report, I find that the error might be caused by the sender has no permission to send emails, I would like to confirm the following information for troubleshooting:

1. Are you send emails via Send As permission?

2. The detailed email addresses of the sender and recipient.

I am not trying to send from a user. I am trying to implement the Direct Send as described in the MS article linked  above, and again below:
How to set up a multifunction device or APPLICATION to send email using Office 365

According to the article I will not need credentials, and will only be able to send within my domain.

As described above I get the same error message with different sender addresses.

It is getting quite frustrating repeating the same information only to have it ignored by different moderators each time. Please read the post and then reply.

Regards,

Rhys

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Rhys,

Thanks for your clarification. 

Now, I know the issue (the error “5.7.51”) you are encountering is that you can’t send via the script via referring to that article. Firstly, I should admit that your understanding is right. Sending from Office 365 via “Direct Send” really doesn’t need an Office 365 mailbox but only an address containing the domain of your Office 365 organization. Secondly, I’d like to say this method is used for the multi-function device but not any script. As a result, it won’t be successful if you send via the script via referring to “Direct Send”.

In addition, Office 365 has little information regarding sending from Office 365 via script (Office 365 users always send from the real mailboxes). I know there might be some third-party article/link about it. Here, I am afraid we can provide limited assistance in helping resolving sending via the script. Your understanding is much appreciated.

Regards,
Alan
-----------------------

* Beware of scammers posting fake support numbers here.

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

While you have all approached with a helpful demeanour, I find no evidence that you follow that up with actual intention to help -  I have found no help in any of what has been said. It has in fact been a waste of time, and includes misinformation. A little effort in reading the post by someone with a little more exchange knowledge than me was all that was required. I got there by searching and learning myself.

@Alan that is plainly wrong. read the article's first sentence and tell me this is only for multifunctions. A cursory thought about what is going on would reveal that this is just as relevant to scripts as it is for MFDs, and you seem to have looked past my requirements and the reality of how IT operations run. There is a reason that the ability to send emails is built into the scripting languages Microsoft have developed.

I guess you are under pressure to post but please save the next post creator some frustration and read their request.

The answer was there in the error message I posted originally (which was then removed) for my privacy although I replaced identifiable info with XXX.

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi Rhys,

Yeah, the first sentence of that article has explained it is for the multi-devices. And, can you show me any official article/link regarding sending from script for Office 365?

For Office 365 Direct Send, it requires 25 port on the device. But, I can’t find any information about it for your script.

Regards,
Alan

-----------------------

* Beware of scammers posting fake support numbers here.

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

@Alan you are wasting your time and mine. This will be my last reply unless you can offer something useful.

Yeah, the first sentence of that article has explained it is for the multi-devices. And, can you show me any official article/link regarding sending from script for Office 365?

For Office 365 Direct Send, it requires 25 port on the device. But, I can’t find any information about it for your script. 

Read the sentence not just the part you want to cherry pick it is for MFDs and applications. 

This article explains how you can send email from devices and business applications when all of your mailboxes are in Office 365.

There is nothing magic about an MFD or application that makes its SMTP traffic different from other SMTP traffic. Don't treat IT as if it's voodoo/magic.

SMTP is on port 25 by default. Both scripts send using SMTP and unless I change the method and specify a different port (which I have had to) they will use port 25. Read a little and stop encumbering people with ignorant replies. Your "help" has been misinformed, incomplete and detrimental.

I have tested the scripts on another tenancy and they work as expected.

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

 
 

Question Info


Last updated January 21, 2025 Views 10,157 Applies to: