我正尝试使用Gmail在C#中发送电子邮件。每当用户收到电子邮件时,我都希望“发件人”标题拥有另一个自己指定的电子邮件地址。任何人都可以告诉我我该怎么做?通过Gmail帐户发送电子邮件问题
MailMessage mailMsg = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(username, password);
MailAddress mailAdd = new MailAddress("[email protected]");
mailMsg.Sender = new MailAddress(username);
mailMsg.From = mailAdd;
//mailMsg.Headers.Add("Sender",username);
mailMsg.Bcc.Add(builder.ToString());
mailMsg.Subject = txtSubject.Text;
mailMsg.Body = txtBody.Text;
mailMsg.IsBodyHtml = chkHtmlBody.Checked;
if (System.IO.File.Exists(txtAttechments.Text))
{
System.Net.Mail.Attachment attechment = new Attachment(txtAttechments.Text);
mailMsg.Attachments.Add(attechment);
}
client.Send(mailMsg);
在上面的代码'用户名'和'密码'字段中包含另一个电子邮件地址和密码。收到的电子邮件有'来自'标头,值为
重复的http://stackoverflow.com/questions/3304699/how-to-set-from-address-to-any-email-other-gmail-in-sending-email-in-net- thro和http://stackoverflow.com/questions/3871577/change-sender-address-when-sending-mail-through-gmail-in-c。基本上,使用Gmail,无法完成(按设计) – 2011-02-14 12:02:00