C# SendGrid-Owin身份电子邮件身份验证

C# SendGrid-Owin身份电子邮件身份验证,c#,smtp,identity,owin,sendgrid,C#,Smtp,Identity,Owin,Sendgrid,我很难通过电子邮件实现Owin Identity 2.0身份验证 下面是我用于smtp客户端配置的代码片段 IdentityConfig.cs SMTP日志 完整日志文件的链接:删除客户端。EnableSsl=true;从代码中分离并检查。它应该会起作用 我已经用“mail.authstp.com”测试过了,它运行良好,您只需要删除client.enablesssl=true;部分代码如下 public class EmailService : IIdentityMessageService

我很难通过电子邮件实现Owin Identity 2.0身份验证

下面是我用于smtp客户端配置的代码片段

IdentityConfig.cs SMTP日志
完整日志文件的链接:

删除客户端。EnableSsl=true;从代码中分离并检查。它应该会起作用

我已经用“mail.authstp.com”测试过了,它运行良好,您只需要删除client.enablesssl=true;部分代码如下

public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        // Credentials:
        string sendGridUserName = "HansMuster456";
        string sentFrom = "OwinIdentityTest@TestDomain.ch";
        string sendGridPassword = "xxxxx";

        // Configure the client
        var client = new System.Net.Mail.SmtpClient("smtp.sendgrid.net", 587);

        client.Port = 587;
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        // Create the credentials:
        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(sendGridUserName, sendGridPassword);

        //client.EnableSsl = true;
        client.Credentials = credentials;

        // Create the message:
        var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination);

        mail.Subject = message.Subject;
        mail.Body = message.Body;

        // Send:
        return client.SendMailAsync(mail);
    }
}
System.Net.Sockets Verbose: 0 : [6456] Socket#53556591::EndReceive(OverlappedAsyncResult#42931033)
System.Net.Sockets Verbose: 0 : [6456] Exiting Socket#53556591::EndReceive()    -> Int32#32
System.Net Error: 0 : [6456] Decrypt failed with error 0X90317.
System.Net.Sockets Verbose: 0 : [6456] Socket#53556591::Dispose()
System.Net Verbose: 0 : [6456] SmtpPooledStream::Dispose #49538252
System.Net Verbose: 0 : [6456] Exiting SmtpPooledStream::Dispose #49538252
public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        // Credentials:
        string sendGridUserName = "HansMuster456";
        string sentFrom = "OwinIdentityTest@TestDomain.ch";
        string sendGridPassword = "xxxxx";

        // Configure the client
        var client = new System.Net.Mail.SmtpClient("smtp.sendgrid.net", 587);

        client.Port = 587;
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        // Create the credentials:
        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(sendGridUserName, sendGridPassword);

        //client.EnableSsl = true;
        client.Credentials = credentials;

        // Create the message:
        var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination);

        mail.Subject = message.Subject;
        mail.Body = message.Body;

        // Send:
        return client.SendMailAsync(mail);
    }
}