Error in programmatically sending mail on behalf of a non-existent email address

Hi,

We use System.Net.Mail.SmtpClient class in C# to send mails using an Exchange 365 mailbox. This is the outline of the code:

System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();

smtpClient.UseDefaultCredentials = false;

smtpClient.Credentials = new System.Net.NetworkCredential("Valid O365 Exchange User Email address", "Password");

smtpClient.Port = 587;

smtpClient.Host = "smtp.office365.com";

smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

smtpClient.EnableSsl = true;

.............

MailMessage msg = new MailMessage();

msg.From = new MailAddress("*** Email address is removed for privacy ***");   // non-existent mailbox address
msg.Sender = new MailAddress("*** Email address is removed for privacy ***");  // Valid O365 user used in credentials above

..............

// add subject, body etc. and send

This was working till recently and in the received mail we used to see sender as "*** Email address is removed for privacy *** on behalf of *** Email address is removed for privacy ***".

However, this has stopped working recently and we are getting error. There is no change in code or the exchange configuration. Please let us know if this is due to any recent change and what is the possible fix for this error:

System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message

Thanks

Pavan

https://www.crowcanyon.com/

Hi  PavanCrowCanyon,

 

Based on the information you provided, I did a lot of research about the code with System.Net.Mai.SmtpClient.  And according to the Microsoft Official document, the API is now obsolete,  some other information about the code, please refer to https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netframework-4.7.2.

 

As the API is obsolete, if the information above cannot help you, concerned the issue is related to the code,  it is recommended that please post a new thread to https://social.msdn.microsoft.com/Forums/en-US/home?sort=relevancedesc&brandIgnore=True&searchTerm=System.Net.Mail.SmtpClient. The forum is focusing on the code and some other developer features related issues,  and the dedicated support engineers there will give some further assistance regarding to your current problem, thanks.

 

Your understanding and patience will be highly appreciated.

 

Regards,

Oliver

 

-----------------------------
* Beware of scammers posting fake support numbers here.
* We are happy and always here to help you, and share the Microsoft 365 for business online information with you.

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 Oliver,

Thanks for your detailed response.

I am not really concerned with System.Net.Mai.SmtpClient here. At this point it is working well for us and our mails are going fine. What we want to know is how to send mail with 'on behalf of' feature with from address as an email that doesn't have a mailbox. This used to work for us till sometime back (we last checked a few weeks back). Looks like it is recently disallowed or some new setting introduced on the Microsoft Exchange online for this. It will be really helpful if we can get to know as what has changed this behavior recently.

Thanks again

Pavan

https://www.crowcanyon.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.

Hello  PavanCrowCanyon,

 

Thanks for your reply and patience.

 

We totally understand noreply@abc.com ( non-existent email address) on behalf of useremail@xyz.com used to work, in this case I want to know if you directly send emails from non-reply@abc.com with the code now, can you send out the emails?  If so, as we are not dedicated with the code to send emails in office 365, concerned you are using the code to use this feature on your side. It is recommended that please ask your question at the MSDN forum which I mentioned above.  The dedicated engineers there are focusing on this kind of problems, and they will give you some further assistance, thanks.  By the way, if you got any updates related to office 365, welcome back to share with us, and we are willing to help you.

 

Your understanding and patience are highly valued.

 

Regards,

Oliver

-----------------------------
* Beware of scammers posting fake support numbers here.
* We are happy and always here to help you, and share the Microsoft 365 for business online information with you.

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 Oliver,

Thanks for your response. I have posted the question in MSDN forum as per your suggestion and I will update the conclusion here if I get one.

Regards,

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.

 
 

Question Info


Last updated October 1, 2021 Views 1,267 Applies to: