[英]Set “From” address when using System.Net.Mail.MailMessage?
I'm trying to send a password reset email, but I'm having trouble figuring out how to specify the sender's address. 我正在尝试发送密码重置电子邮件,但是在弄清楚如何指定发件人地址时遇到了麻烦。
Here's what I'm trying to do: 这是我想做的事情:
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);
I'm sure it's possible, so how can I accomplish this in ASP.Net? 我确信这是有可能的,那么如何在ASP.Net中完成呢?
It turns out I was getting ahead of myself. 原来我在超越自己。
Removing Address
from mail.From.Address
allowed me to set the value, but needed the type MailAddress
. 从
mail.From.Address
删除Address
允许我设置值,但需要类型MailAddress
。
Here's the solution: 解决方法如下:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.