Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 5 标识2.1电子邮件服务_Asp.net Mvc 5_Email_Sendgrid - Fatal编程技术网

Asp.net mvc 5 标识2.1电子邮件服务

Asp.net mvc 5 标识2.1电子邮件服务,asp.net-mvc-5,email,sendgrid,Asp.net Mvc 5,Email,Sendgrid,我正在开发一个MVC 5互联网应用程序,希望在我的应用程序部署到Azure时使用SendGrid服务发送电子邮件 我发现了一些资源链接,但是我使用的每个不同的代码实现发送电子邮件的速度都非常慢。我已选择使用此链接中的代码: 这是我的密码: public class EmailService : IIdentityMessageService { public Task SendAsync(IdentityMessage message) { // Credenti

我正在开发一个MVC 5互联网应用程序,希望在我的应用程序部署到
Azure
时使用
SendGrid
服务发送电子邮件

我发现了一些资源链接,但是我使用的每个不同的代码实现发送电子邮件的速度都非常慢。我已选择使用此链接中的代码:

这是我的密码:

public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        // Credentials:
        var sendGridUserName = "myusername";
        var sentFrom = "test@email.com";
        var sendGridPassword = "mypassword";

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

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

        // Creatte 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);
    }
}
发送电子邮件需要很多分钟。为什么会这样?电子邮件的平均发送速度应该有多快?我是否需要以任何方式优化我的代码?另外,除了使用
SendGrid
,还有更好的资源可以使用吗


提前感谢。

在Sendgrid文档中的某个地方(不幸的是现在找不到),我看到了这样的建议:如果您使用他们的REST API端点而不是SMPT,电子邮件将更快到达。Sendgrid提供了C#库来使用他们的API。试一试。

可能SendGrid正在推迟或延迟您的发送。SendGrid仪表板中是否有延迟或延迟活动


您还可以连接到以查看电子邮件的具体情况。

请问您是否遇到了“试图以访问权限禁止的方式访问套接字”错误,以及您如何缓解该错误?嗯,REST API会更快,但不会快几分钟。不过,使用RESTAPI还有其他原因。