SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

CSOM SendEmail unreliable #4929

Open cwdata opened 4 years ago

cwdata commented 4 years ago

Category

Expected or Desired Behavior

We are using the method Microsoft.SharePoint.Client.Utilities.Utility.SendEmail(ClientContext, EmailProperties) to send mails from a backend web API hosted in Azure App Service to Office 365 users. We are expecting to get all of those mails delivered to the recipient.

Observed Behavior

This works about 90% of the time. Sometimes it fails. When it fails: The subsequent call to ClientContext.ExecuteQuery() fails with an error stating that the IP of the sender has been banned: Microsoft.SharePoint.Client.ServerException: Mailbox unavailable. The server response was: 5.7.606 Access denied, banned sending IP [52.105.0.167]. To request removal from this list please visit https://sender.office.com/ and follow the directions. For more information please go to http://go.microsoft.com/fwlink/?LinkID=526655 (AS16012609) [DB5EUR03FT022.eop-EUR03.prod.protection.outlook.com] As this is happening on the Microsoft side, the banned IP is obviously not our server. It is one of Microsofts own mail servers. The IP address varies but the one mentioned above is the one that we mostly see in the error message. I also tried to delist it using the link from the error but that didn't help.

As I've said the mail is being sent by Microsoft's own servers. Interestingly some of those seem to be blacklisted at other Microsoft servers. We implemented a retry mechanism that seems to solve it because on the second or third try the mail will get sent by another server which is OK.

Also important to know:

Steps to Reproduce

Sadly it is hard to reproduce. In other words it's not like "do this" and then it fails. You'll have to send a bunch of mails throughout the day to see it happen.

Question

Is there anything we could do to avoid the blacklisted servers? This is still a test system and I'm afraid of using that in production as those mails are important and there's no guarantee that we won't get 3 times in a row on a blacklisted server.

msft-github-bot commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

MZabal commented 4 years ago

Same issue here,
Using the method SendMail

var emailp = new EmailProperties();
emailp.To = to;
emailp.From = "";
emailp.Body = body;
emailp.Subject = subject;
Utility.SendEmail(ctx, emailp);
ctx.ExecuteQueryRetry();

We are getting the following exception:

Mailbox unavailable. The server response was: 5.7.606 Access denied, banned sending IP [xxx.xxx.xxx.xxx]. 
To request removal from this list please visit https://sender.office.com/ and follow the directions. 
For more information please go to http://go.microsoft.com/fwlink/?LinkID=526655 (AS16012609) [VE1EUR03FT006.eop-EUR03.prod.protection.outlook.com] 

This has been happening for a while and delisting the IPs seems not to work at all....

IonutLupsan commented 4 years ago

The same issue happens here too, with an extra flavor: a random Unable to send to all recipients exception, even if is only a maximum of 5 email recipients and all of them have active and working internal accounts.

mikeplate commented 4 years ago

Same issue here but I'm using SharePoint REST API. Our custom solution sends two emails in sequence and the first one usually works but the second gets this Access denied error. This seems to have started a week or two ago? Before that, we never had any issues (even though we don't use this solution every day).

I don't think this is a problem in CSOM, but in the internal operations of SharePoint and Exchange Online where Microsoft basically has blacklisted themselves.

simonfalun commented 4 years ago

I also have the same issue, through REST - SP.Utilities.Utility.SendEmail. I've tried removing the listing but when I next time got another IP in the error message I realized it would be a never ending job.

{ "readyState":4, "responseText":"{ \"error\":{ \"code\":\"-1, System.Net.Mail.SmtpFailedRecipientException\", \"message\":{ \"lang\":\"sv-SE\", \"value\":\"Mailbox unavailable. The server response was: 5.7.606 Access denied, banned sending IP [104.146.225.177]. To request removal from this list please visit https://sender.office.com/ and follow the directions. For more information please go to http://go.microsoft.com/fwlink/?LinkID=526655 (AS16012609) [AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com]\" } } }", "responseJSON":{ "error":{ "code":"-1, System.Net.Mail.SmtpFailedRecipientException", "message":{ "lang":"sv-SE", "value":"Mailbox unavailable. The server response was: 5.7.606 Access denied, banned sending IP [104.146.225.177]. To request removal from this list please visit https://sender.office.com/ and follow the directions. For more information please go to http://go.microsoft.com/fwlink/?LinkID=526655 (AS16012609) [AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com]" } } }, "status":500, "statusText":"error" }

toblum commented 4 years ago

The same here:

Error sending e-mailMicrosoft.SharePoint.Client.ServerException: Mailbox unavailable. The server response was: 5.7.606 Access denied, banned sending IP [52.105.xxx.xxx]. To request removal from this list please visit https://sender.office.com/ and follow the directions. For more information please go to http://go.microsoft.com/fwlink/?LinkID=526655 (AS16012609) [DB5EUR03FT052.eop-EUR03.prod.protection.outlook.com]
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at ...

I wonder if it's related to: https://admin.microsoft.com/AdminPortal/Home#/MessageCenter?id=MC192693

Best regards Tobias

sebastian-dor commented 4 years ago

Experiencing the same issues here.

cwdata commented 4 years ago

OK, seems that Microsoft is completely ignoring this issue. If anyone has access to premier support it would be great if he could open a ticket there to force them into a reaction.

NotAlexx commented 4 years ago

Hey @cwdata

I have used our premier support and this is the word from microsoft.

Short-term solution: Access https://sender.office.com/ and follow the steps to delist the blocked IP your get from the error message. Customer may get different IPs when encounter this issue, so we need to delist each of them from black list. If you cannot get the IP address, contact us with error message and timestamp to check it from backend log.

Long-term solution: The Exchange Online Product Group has backlogged work items to address this issue, but there is no ETA for now.

cwdata commented 4 years ago

Thanks @NotAlexx at least we now know, that Microsoft is tracking this issue. As we and others have made the experience that delisting the blocked IPs does not help this will be a waste of time. So we will have to wait. Looking at our logs most of the times one retry is enough to get the mail sent. We rarely need 2 retries.

NotAlexx commented 4 years ago

No worries, in the meantime I am doing an http request to a flow and sending emails from there.

Cheers

lucabandMSFT commented 4 years ago

Folks, I'm removing the "needs MS review" tag here as a team in Microsoft (Exchange) is already aware of the issue and has a workitem assigned to solve it (as mentioned before). Happy to leave this open here and close it once the fix has been reported to be deployed

proce commented 3 years ago

I was wondering if there have been any updates on the ETA for the fix to address this issue?

We have tried numerous times using https://sender.office.com/ to delist the blocked IP’s but to no avail.

cwdata commented 3 years ago

@proce you'd better not bet on a fix for this issue. It's not like they'll have to code for weeks to correct it, it's just a matter of learning what a 'Whitelist' is and using it on their servers. They would have done it months ago if they had wanted to...

Kamalasekaran commented 3 years ago

We were given 235 Emails but Receive only approximately 90 Emails.