下面是我发送邮件的代码...
public void SendBy(string to, string subject, string body)
{
MailMessage nM = new System.Net.Mail.MailMessage();
nM.To.Add("abc@compulynx.org");
nM.Subject = subject;
nM.Attachments.Add(new Attachment(oStream, Fname));
nM.Body = body;
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
SmtpClient client = new SmtpClient(settings.Smtp.Network.Host);
client.Credentials = new NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
client.EnableSsl = true;
client.Send(nM);
}
这是我的网络配置代码...
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="xyz@gmail.com" >
<network host="smtp.gmail.com"
defaultCredentials="false" userName="xyz@gmail.com" password="xyz"
port="587"/>
</smtp>
</mailSettings>
</system.net>
此代码工作正常,但我将如何更改发件人显示名称,通常我们这样使用
mM.From = new MailAddress("xyz@gmail.com","xyz");
但就我而言,我没有在任何地方写发件人邮件地址,我只是从网络配置中获取,然后我将如何更改该名称..我的会话中有当前登录用户,我想将该名称显示为发件人。 ..