【问题标题】:Is it possible to have a different sender email and configuration email to send email from MimeKit in ASP.Net Core?是否可以使用不同的发件人电子邮件和配置电子邮件从 ASP.Net Core 中的 MimeKit 发送电子邮件?
【发布时间】:2021-04-15 10:08:56
【问题描述】:

我添加了将电子邮件发送给接收方的代码。截至目前,我需要在“发件人”电子邮件和“用户名”(配置电子邮件)中添加相同的电子邮件地址以发送电子邮件,否则它将失败。但我希望有不同的“发件人”电子邮件,而不是询问用户密码并使用一个配置邮件发送电子邮件,以便多个用户可以使用此服务发送电子邮件。有可能吗?

这是我的代码:

public async Task<string> Send(string from, string to, string subject, string html, string userName, string password)
{
    // create message
    var email = new MimeMessage();
    email.From.Add(MailboxAddress.Parse(from));
    email.To.Add(MailboxAddress.Parse(to));
    email.Subject = subject;
    email.Body = new TextPart(TextFormat.Html) { Text = html };
    using var smtp = new SmtpClient();
    smtp.Connect("smtp.live.com", 587, SecureSocketOptions.StartTls);
    smtp.Authenticate(userName, password);
    smtp.Send(email);
    smtp.Disconnect(true);
    return "Email Set";
}

【问题讨论】:

    标签: asp.net-core email mimekit email-address


    【解决方案1】:

    是的,但您需要使用私有 SMTP 服务器,该服务器将接受 From: 标头和身份验证命令中的不同地址。据我所知,广泛使用的公共 SMTP 服务器都不允许这样做。

    【讨论】:

      猜你喜欢
      • 2016-03-10
      • 2021-03-15
      • 2018-09-15
      • 1970-01-01
      • 2016-11-02
      • 2012-06-11
      • 2011-02-13
      • 2021-11-19
      • 1970-01-01
      相关资源
      最近更新 更多