我是 ASP.Net core 的初学者。实际上我正在使用 ASP.Net Core 3.0。我想向多个收件人发送电子邮件。我可以使用IEmailSender接口吗?或者有什么建议吗?
我的 IEmailSender 实现是这样的,
public class EmailSender : IEmailSender
{
private string host;
private int port;
private bool enableSSL;
private string userName;
private string password;
public EmailSender(string host, int port, bool enableSSL, string userName, string password)
{
this.host = host;
this.port = port;
this.enableSSL = enableSSL;
this.userName = userName;
this.password = password;
}
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
var client = new SmtpClient(host, port)
{
Credentials = new NetworkCredential(userName, password),
EnableSsl = enableSSL
};
return client.SendMailAsync(
new MailMessage(userName, email, subject, htmlMessage) { IsBodyHtml = true }
);
}
}
谁能帮我?
The MailMessage.To
property https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage.to?view=netcore-3.0属于类型邮件地址集合 https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.mailaddresscollection?view=netcore-3.0。这意味着,您可以使用Add
添加多个收件人的方法。
MailMessage message = new MailMessage();
message.To.Add(new MailAddress("[email protected] /cdn-cgi/l/email-protection"));
message.To.Add(new MailAddress("[email protected] /cdn-cgi/l/email-protection"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)