Base solution for your next web application
Open Closed

Can't send mail using office365 using MailMessage class #10277


User avatar
0
andrescarranza created
  • What is your product version? ** 9.3 **
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? Net Core

Hi, I'm having an exception when sending mails using smtp.office365.com.

When I use the EmailSender class, if I use the methods

Task SendAsync(string to, string subject, string body, bool isBodyHtml = true); Task SendAsync(string from, string to, string subject, string body, bool isBodyHtml = true);

I don't experience any problem.

But, when I use this method

Task SendAsync(MailMessage mail, bool normalize = true);

I have this exception:

"Error SendMailDomainService.SendMail: System.Exception: Error SendMailDomainService.SendMail\r\n ---> MailKit.Net.Smtp.SmtpCommandException: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:5D1B0000, 1.36674:01000000, 1.61250:00000000, 1.45378:02000000, 1.44866:00000000, 1.36674:7A000000, 1.61250:00000000, 1.45378:05000000, 1.44866:00140000, 1.36674:0A000000, 1.61250:00000000, 1.45378:16000000, 1.44866:21210000, 1.36674:0E000000, 1.61250:00000000, 1.45378:3A210000, 1.44866:36020000, 16.55847:6E110000, 17.43559:0000000030020000000000000000000000000000, 20.52176:140FE18F1700F01F0201DB82, 20.50032:140FE18F8717F01F07000000, 0.35180:1F000130, 255.23226:0A000000, 255.27962:7A000000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:37000000, 0.35250:1F001336, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:5E000000, 1.36674:32000000, 1.61250:00000000, 1.45378:63000000, 1.44866:01000000, 16.55847:CA000000, 17.43559:0000000078030000000000000000000000000000, 20.52176:140FE18F170010107E000000, 20.50032:140FE18F871700002D000000, 0.35180:83000000, 255.23226:0A001380, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:37000000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:3C000000, 0.38698:05000780, 0.37692:01000000, 0.37948:22000000, 5.33852:00000000534D545000000000, 7.36354:010000000000010907000000, 4.56248:DC040000, 7.40748:010000000000010B0B000000, 7.57132:000000000000000000000000, 1.63016:32000000, 4.39640:DC040000, 8.45434:454DE93DF0EC724BA7317267A0E8E4C400000000, 1.46798:04000000, 5.10786:0000000031352E32302E343036352E3032333A425935505231344D42333833323A35666636393031362D333662382D346531322D613534372D3236323337653362666536613A383632383400, 7.51330:773A9765AD05D90807000000, 0.39570:D9000000, 1.55954:0A000000, 0.49266:02000000, 1.33010:0A000000, 2.54258:00000000, 0.40002:7A000000, 1.56562:00000000, 1.64146:32000000, 1.33010:32000000, 2.54258:DC040000, 255.1750:0A006136, 255.31418:82000000, 0.22753:D3000000, 255.21817:DC040000, 0.64418:87000000, 4.39842:DC040000, 0.41586:03000336, 4.60547:DC040000, 0.21966:DD000000, 4.30158:DC040000 [Hostname=BY5PR14MB3832.namprd14.prod.outlook.com]\r\n at MailKit.Net.Smtp.SmtpClient.DataAsync(FormatOptions options, MimeMessage message, Int64 size, Boolean doAsync, CancellationToken cancellationToken, ITransferProgress progress)\r\n at MailKit.Net.Smtp.SmtpClient.SendAsync(FormatOptions options, MimeMessage message, MailboxAddress sender, IList1 recipients, Boolean doAsync, CancellationToken cancellationToken, ITransferProgress progress)\r\n at MailKit.Net.Smtp.SmtpClient.SendAsync(FormatOptions options, MimeMessage message, MailboxAddress sender, IList1 recipients, Boolean doAsync, CancellationToken cancellationToken, ITransferProgress progress)\r\n at Abp.MailKit.MailKitEmailSender.SendEmailAsync(MailMessage mail)\r\n at Abp.Net.Mail.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize)\r\n at XassCoreCloud.Apps.Common.Jobs.SendMailDomainService.SendMailWithMultipleAttachments(String FromEmailAddress, List1 listEmailAddress, String subject, String body, List1 pathAtachFiles) in D:\Repos\dev\Xass4.0CoreCloud\XassCoreCloud_Backend\src\XassCoreCloud.Application\Apps\Common\MailSend\SendMailDomainService.cs:line 88\r\n --- End of inner exception stack trace ---\r\n at XassCoreCloud.Apps.Common.Jobs.SendMailDomainService.SendMailWithMultipleAttachments(String FromEmailAddress, List1 listEmailAddress, String subject, String body, List1 pathAtachFiles) in D:\Repos\dev\Xass4.0CoreCloud\XassCoreCloud_Backend\src\XassCoreCloud.Application\Apps\Common\MailSend\SendMailDomainService.cs:line 95\r\n at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)\r\n at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)\r\n at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)\r\n at Abp.Runtime.Validation.Interception.ValidationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)\r\n at XassCoreCloud.Apps.ERP.Sales.SalesInvoicesAppService.SendInvoiceMail(SalesInvoiceMailDto salesInvoiceMailDto) in D:\XXXXXXXXXXXXXXXXXXXXX\SalesInvoicesAppService.cs:line 1109"

I'm using this method because I need to send attachments in the email. Please notice that if i use the method, without attachments, the result is the same exception.

I have tried several configurations in Office365 to achieve the result, without success. Please note i don't have this problem if I use a gmail account.

Please your help.


1 Answer(s)