我需要使用COM在c#中发送电子邮件。我使用了以下代码:
var fromAddress = new MailAddress("mai@live.com", "From mai live");
var toAddress = new MailAddress("test@apol.eu", "to test");
const string subject = "Subject test email";
const string body = "<h1><b>Body test email</b></h1>";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("mail@gmail.com", "mdp"),
Timeout = 30 * 1000,
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true,
BodyEncoding = System.Text.UTF8Encoding.UTF8
})smtp.Send(message);
此代码对我有用,但是所有收到的邮件都是来自Gmail的! 任何想法如何更改发件人地址?