我送下面这个模式的邮件:从邮件中的用户名设置?
public static bool SendPasswordMail(MembershipUser user, Control owner, string password)
{
var definition = new MailDefinition { BodyFileName = string.Concat(AccountRoot, "password.htm"), IsBodyHtml = true };
var subject = "Your new password - {0}".FormatWith(ApplicationConfiguration.ApplicationName);
var data = ExtendedData(DefaultData, subject, user);
data.Add("<%Password%>", password);
return definition.CreateMailMessage(user.Email, data, owner).Send(subject);
}
public static bool Send(this MailMessage message, string subject)
{
try
{
using (message)
{
message.Subject = subject;
using (var client = new SmtpClient())
client.Send(message);
}
}
catch
{
return false;
}
return true;
}
,而不是设置受“新密码 - 网站”,我想从用户名设置为“网站”,并受到公正“你的新密码”。但我不知道如何设置从用户名。
我在web.config
smtp
元素看起来是这样的:
<smtp deliveryMethod="Network" from="[email protected]">
<network host="localhost" port="25" userName="[email protected]" password="******" />
</smtp>
无论如何,不要返回true/false,而是使用void并在需要时抛出异常 – abatishchev
您不想通过邮件发送密码。这不是必要的和安全风险! – ccellar