Share via

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

Anonymous
2019-02-25T08:26:04+00:00

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("******@abc.com");   // non-existent mailbox address

msg.Sender = new MailAddress("******@xyz.com");  // 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 "******@abc.com on behalf of ******@xyz.com".

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/

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2019-02-26T17:52:17+00:00

    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 answer helpful?

    0 comments No comments
  2. Anonymous
    2019-02-26T03:00:04+00:00

    Hello  PavanCrowCanyon,

    Thanks for your reply and patience.

    We totally understand ******@abc.com ( non-existent email address) on behalf of ******@xyz.com used to work, in this case I want to know if you directly send emails from ******@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

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-02-25T19:04:25+00:00

    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 answer helpful?

    0 comments No comments
  4. Anonymous
    2019-02-25T10:07:20+00:00

    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

    Was this answer helpful?

    0 comments No comments