【发布时间】:2020-05-18 10:13:29
【问题描述】:
您好,我正在使用 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("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>.");
我希望在注册后立即发送消息,以便用户可以确认电子邮件.. 有什么遗漏提前谢谢
【问题讨论】:
标签: asp.net-core blazor smtpclient