1

When I try to send an email via MailKit in ASP.Net Core, I get the exception:

5.3.4 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:69000000, 17.43559:0000000060010000000000000000000000000000, 20.521

Code send Email:

 try { var fromAddress = "[email protected]"; var fromAdressTitle = "no-reply"; var toAddress = "[email protected]"; var toAdressTitle = "Test sending email"; var subject = "Hello World!"; var bodyContent = "content message"; var mimeMessage = new MimeMessage(); mimeMessage.From.Add(new MailboxAddress(fromAdressTitle, fromAddress)); mimeMessage.To.Add(new MailboxAddress(toAdressTitle, toAddress)); mimeMessage.Subject = subject; mimeMessage.Body = new TextPart("plain") { Text = bodyContent }; using (var client = new SmtpClient()) { client.Connect("smtp-mail.outlook.com", 587,SecureSocketOptions.StartTls); client.Authenticate("[email protected]", "mypass"); client.Send(mimeMessage); Console.WriteLine("The mail has been sent successfully !!"); Console.ReadLine(); client.Disconnect(true); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } 

Please help explain the reason of exception and how to fix this issue. Thanks.

2
  • Did you ever figure out what the issue is? I'm facing the same problem Commented Apr 7, 2018 at 20:28
  • This problem only existed in outlook, but with Gmail it was not a problem and works correctly. Commented Apr 8, 2018 at 6:06

2 Answers 2

3

SendAsDeniedException means it doesn't allow you to send an email from domain.com. It (the fromAddress field) must be var fromAddress = "[email protected]". Here are 2 similar issues:

Sign up to request clarification or add additional context in comments.

3 Comments

That's not the reason, because when i send via "smtp.gmail.com" and the same fromAddress it work fine.but when i send via smtp-mail.outlook.com this is not work.
This is the policy of Microsoft. You can't send as another person or domain from outlook.com. This is the meaning of **Send As** Denied Exception.
I tested it.i set fromAddress to real Email Address but when sending Email an exception occur: The SMTP server has unexpectedly disconnected.
0

First, you don't set correct email and pass.

and you must set Credentials like above:

 var credentials = new NetworkCredential("[email protected]","yourpass"); var client = new SmtpClient(smtpEmail.smtp) { Port = 587, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = true, Credentials = credentials }; 

4 Comments

What library did you use?
I don't use library.
Microsoft officially announced the SmtpClient outdated in ASP.Net Core. more info
yes, I know. but I still use full framework and I don't migrate to .net core.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.