SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
smtpClient.Credentials = new NetworkCredential("xxxxx@gmail.com", "password");
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//mail.From = new MailAddress("xxx1@gmail.com");
mail.To.Add("XX2@gmail.com");
mail.Subject = "Test mail";
mail.Body = "This is test mail, with test content";
smtpClient.Send(mail);
在上面的代码中,为什么mail.From是强制性的?甚至我在 smtpClient.Credentials 中指定了邮件 ID。
即使我使用一些邮件 ID 指定了mail.From,收件人也不会从该邮件地址接收邮件,而是从我在smtpClient.Credentials中指定的xxxxx@gmail.com接收邮件。