Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/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 core ASP.NET CORE中发送电子邮件的延迟_Asp.net Core_Blazor_Smtpclient - Fatal编程技术网

Asp.net core ASP.NET CORE中发送电子邮件的延迟

Asp.net core ASP.NET CORE中发送电子邮件的延迟,asp.net-core,blazor,smtpclient,Asp.net Core,Blazor,Smtpclient,您好,我正在使用blazor构建一个web应用程序,blazor向注册用户发送电子邮件激活链接,正在发送电子邮件激活,但问题是注册用户接收激活链接的时间太长(大约5分钟)。这是我的密码 我的接口类 public interface IEmailServices { Task SendEmailAsync(string toAddress, string subject, string body); } 我的邮件发件人类 public class EmailSender : IEmai

您好,我正在使用blazor构建一个web应用程序,blazor向注册用户发送电子邮件激活链接,正在发送电子邮件激活,但问题是注册用户接收激活链接的时间太长(大约5分钟)。这是我的密码

我的接口类

 public interface IEmailServices
{
    Task SendEmailAsync(string toAddress, string subject, string body);
}
我的邮件发件人类

public class EmailSender : IEmailServices
{
    public async Task SendEmailAsync(string emailDestination, string subject, string htmlMessageBody )
    {

        MailMessage ms = new MailMessage("myemail@domain.com", emailDestination, subject,htmlMessageBody);
        ms.IsBodyHtml = true;
        string user = "myemail@domain.com";
        string passcode = "mypassword";
        SmtpClient smtpServer = new SmtpClient("mail.domain.com");
        smtpServer.Credentials = new System.Net.NetworkCredential(user, passcode);
        try
        {
            await smtpServer.SendMailAsync(ms);
        }
        catch (Exception ex)
        {

            throw ex;
        }

    }       

}
这里是我发送信息的地方

//Generate Email confirmation link
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                        $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
//生成电子邮件确认链接
var code=wait_userManager.GenerateEmailConfirmationTokenAsync(用户);
code=WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl=Url.Page(
“/Account/ConfirmEmail”,
pageHandler:null,
值:new{area=“Identity”,userId=user.Id,code=code},
协议:请求。方案);
等待_emailSender.sendmailasync(Input.Email,“确认您的电子邮件”,
$“请确认您的帐户。”);

我希望信息在注册后立即发送,以便用户可以确认电子邮件。。是否有我遗漏的东西提前感谢

您似乎没有做任何会产生大量电子邮件的事情,因此这不会花费很长时间。我的建议是在测试环境中设置应用程序,将SMTP连接设置为您在配置中有权访问的电子邮件帐户。(即使是gmail帐户也可以工作,但你必须适当地设置gmail安全性。)然后,在调试模式下运行你的应用程序,断点位于
wait smtpServer.SendMailAsync(ms)
,然后从该调用继续(VS中的F5)向前执行
sendmail Async()
,让应用程序继续运行。这将允许确认电子邮件是否已发送,并让您了解问题是否在完全发送电子邮件之前出现。在开始测试之前,请确保您已登录到正在测试的电子邮件帐户,然后跳入“电子邮件帐户已发送”文件夹,并检查它是否显示已发送的电子邮件。如果发送电子邮件需要很长时间,则问题在于应用程序的SMTP连接。如果发送的时间很短,但到达收件人仍然需要很长时间,这与电子邮件帐户或连接到它们的客户端有关(认为Outlook中的发送/接收间隔设置太长),但不一定与您的应用程序有关。这将有助于你确定问题,这样你就知道你在处理什么了

好的,谢谢,我想问题在于主机提供商SMTP,我登录到邮件服务器并发送了一条消息,这并不需要很长时间,但从我的应用程序它需要很长时间。