我正在尝试使用以下代码在 C# 中使用 gmail SMTP 发送电子邮件
MailMessage message = new MailMessage();
message.To.Add("my email");
message.Subject = "subject";
message.From = new MailAddress("any email");
message.Body = "body";
message.Attachments.Add(new System.Net.Mail.Attachment(path));
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("my user", "my pass");
smtp.Send(message);
当我收到电子邮件时,FROM字段已填充my user
。我正在使用UseDefaultCredentials
as false
。当我查看结果时,FROM字段填充有my user
. FROM字段不应该填写any email
吗?如何使用any email
发件人发送电子邮件?