【问题标题】:Set "From" address when using System.Net.Mail.MailMessage?使用 System.Net.Mail.MailMessage 时设置“发件人”地址?
【发布时间】:2013-06-19 03:46:16
【问题描述】:

我正在尝试发送密码重置电子邮件,但我无法确定如何指定发件人的地址。

这是我想要做的:

MailMessage mail = new MailMessage();
mail.From.Address = "support@mycompany.com";
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "<a href=\"" + url + "\">Click here to reset your password.</a>";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);

我确信这是可能的,那么我如何在 ASP.Net 中实现这一点?

【问题讨论】:

  • 你的代码是什么?你试过什么?
  • 你是在使用 MailMessage 类还是别的什么?
  • 对不起,我的错。那么你的代码有什么问题?不行吗?

标签: c# asp.net-mvc email system mailmessage


【解决方案1】:

事实证明我走在了前面。

mail.From.Address 中删除Address 允许我设置值,但需要MailAddress 类型。

解决办法如下:

MailMessage mail = new MailMessage();
mail.From = new MailAddress("support@mycompany.com");
mail.To.Add(Email);
mail.Subject = "Forgot Password";
mail.Body = "<a href=\"" + url + "\">Click here to reset your password.</a>";
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);

【讨论】:

  • 太好了,很高兴您发布了自己的解决方案。
猜你喜欢
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
  • 2011-05-13
  • 2018-03-10
  • 2011-07-22
  • 2010-12-19
  • 1970-01-01
相关资源
最近更新 更多