[他正在使用blazor构建一个Web应用程序,该应用程序将电子邮件激活链接发送给注册用户,正在发送电子邮件激活,但是这里的问题是注册用户接收激活链接花费的时间太长(大约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("[email protected]", emailDestination, subject,htmlMessageBody);
ms.IsBodyHtml = true;
string user = "[email protected]";
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>.");
我希望在注册后立即发送邮件,以便用户可以确认电子邮件。
[我正在使用blazor构建一个Web应用程序,该应用程序将电子邮件激活链接发送给注册用户,正在发送电子邮件激活,但是这里的问题花费的时间太长(大约5分钟)...
await smtpServer.SendMailAsync(ms);
的断点运行您的应用程序,然后继续(在VS中为F5)从该调用转到执行SendEmail Async()
,让应用继续运行。这样可以确认电子邮件已发送,还可以让您深入了解问题是否在完全发送电子邮件之前。在开始之前,请确保您已登录要测试的电子邮件帐户,然后跳至电子邮件帐户“已发送”文件夹并检查其是否显示已发送的电子邮件。如果电子邮件发送时间很长,则问题出在应用程序的SMTP连接中。如果发送顺序很短,但仍然需要花费很长时间才能到达收件人,则它与电子邮件帐户或连接到它们的客户端有关(认为Outlook中的“发送/接收”间隔设置太长),但不是一定是您的应用程序。这应该可以帮助您确定问题所在,以便您了解要处理的问题。