微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我在尝试通过 .net 5 System.Net.Mail

如何解决为什么我在尝试通过 .net 5 System.Net.Mail

我正在使用 .net 5 从后端向 Outlook 中的同一电子邮件客户端发送电子邮件。我尝试发送到不同的电子邮件,但是,我仍然收到相同的错误消息。使用调试,我发现异常被捕获在代码“client.Send(message);”上。这是出现错误消息的时候。为什么我会收到此错误消息,我该如何解决

错误信息

> Exception has occurred: CLR/System.Net.Mail.SmtpException
An exception of type 'System.Net.Mail.SmtpException' occurred in softwareapp.dll but was not handled in user code: 'Transaction Failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:OutboundSpamException; Failed to process message due to a permanent exception with message WASCL UserAction verdict is not None. Actual verdict is Suspend,ShowTierUpgrade. OutboundSpamException: WASCL UserAction verdict is not None. Actual verdict is Suspend,ShowTierUpgrade. [Hostname=LNXP265MB0668.GBRP265.PROD.outlook.com]'
   at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode,String serverResponse)
   at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
   at System.Net.Mail.SmtpConnection.OnClose(Object sender,EventArgs args)
   at System.Net.ClosableStream.Close()
   at System.Net.Mail.MailWriter.Close()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at Controllers.ContactUsController.contactUsSubmitForm(ContactUsSubmitForm contactUsSubmitForm) in \Controllers\ContactUsController.cs:line 39
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.<>c__displayClass33_0.<WrapVoidMethod>b__0(Object target,Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.VoidResultExecutor.Execute(IActionResultTypeMapper mapper,ObjectMethodExecutor executor,Object controller,Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next,Scope& scope,Object& state,Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterasync()

代码

[HttpPost()]  
public void sendEmail()
{
    try
    {             
        string _sender = "myemail@outlook.com";
        string _password = "password";
        SmtpClient client = new SmtpClient("smtp-mail.outlook.com");

        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        System.Net.NetworkCredential credentials =
            new System.Net.NetworkCredential(_sender,_password);
        client.EnableSsl = true;
        client.Credentials = credentials;

        MailMessage message = new MailMessage(_sender,"myemail@outlook.com");
        message.Subject = "c sharp test email";
        message.Body = "c sharp body of email";
            
        client.Send(message);  //where the code stops working and error message appears up
            
    }
    catch (Exception)
    {
        throw;
    }        
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。