【问题标题】:When sending an email via C# SmtpClient, why does the recipient see the username and not the sender or from email?通过 C# SmtpClient 发送电子邮件时,为什么收件人看到用户名而不是发件人或来自电子邮件?
【发布时间】:2016-07-27 08:38:35
【问题描述】:

使用 SmtpClient 发送电子邮件时,电子邮件发送成功,但收件人将 Smpt 主机的用户名视为发件人,而不是 MailMessage 中指定的发件人或发件人电子邮件。

代码

MailMessage mail = new MailMessage("from@email.com", "to@email.com");
mail.Subject = "subject";
mail.Body = "body";
mail.IsBodyHtml = true;
mail.Sender = "from@email.com";

SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = smpt.gmail.com;
client.Credentials = new NetworkCredential("username@gmail.com", "password");
client.EnableSsl = true;
client.Send(mail);

收到的结果电子邮件将 username@gmail.com 显示为发件人/发件人/回复地址,而不是 from@email.com。

是否可以在收件人电子邮件中将 from@email.com 显示为发件人,而不是 username@gmail.com?

【问题讨论】:

  • gmail 不允许使用不同的电子邮件地址进行重定向。他们将标题更改为发送人的地址。
  • 以为会是这样。有什么建议可以实现我的需要 - 将发件人显示为 from@email.com?
  • 您必须通过与 gmail 不同的电子邮件提供商。

标签: c# .net smtp gmail smtpclient


【解决方案1】:

许多 smtp 提供商会使用 client.Credentials 覆盖您的 mail.Sender,以尽量减少网络钓鱼攻击和一般垃圾邮件。因此,如果您将president@bankofamerica.com 放在您的mail.Sender 中,您就不会欺骗收件人,因为收件人会看到client.Credentials。

【讨论】:

    猜你喜欢
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2014-12-15
    • 2022-06-27
    • 2023-04-06
    • 2011-02-13
    相关资源
    最近更新 更多