我正在尝试发送密码重置电子邮件,但我无法确定如何指定发件人的地址。
这是我正在尝试做的事情:
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中实现这一目标呢?
答案 0 :(得分:16)
事实证明我已经超越了自己。
从Address
删除mail.From.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);