在 C# 中,我有一种通过 gmail 帐户发送电子邮件的方法。当我在 Microsoft Outlook 中打开电子邮件时,发件人地址显示为 gmail 地址,而不是我在标题中使用的 strFromAddress。
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.EnableSsl = true;
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new NetworkCredential("***@gmail.com", "*****");
var strFromAddress = "no-repl@demuynck-printing.be";
var strToAddress = "sander@demuynck-media.be";
var strSubject = "Album: '" + lbltitel.Text + "' bestelling";
var strBody = "<html><head>";
// new instance of MailMessage
MailMessage mailMessage = new MailMessage();
// Sender Address
mailMessage.From = new MailAddress(strFromAddress);
// mailMessage.Headers("Selexion Clix Demuynck <no-reply@demuynck-printing.be>");
// mailMessage.Bcc.Add(new MailAddress("no-reply@demuynck-printing.be"));
// Recepient Address
mailMessage.To.Add(new MailAddress(strToAddress));
mailMessage.Headers.Add("Reply-To", "info@demuynck-printing.be");
// Subject
mailMessage.Subject = strSubject;
// Body
mailMessage.Body = strBody;
// format of mail message
mailMessage.IsBodyHtml = true;
// new instance of Smtpclient
smtp.Send(mailMessage);