【发布时间】:2012-03-01 08:32:07
【问题描述】:
我不明白为什么这段代码不起作用。我收到一条错误消息,提示无法分配属性
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.To = "user@hotmail.com"; // <-- this one
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
【问题讨论】:
-
Nore 如果您尝试通过 SMTP 通过 gmail 发送,您需要允许不太安全的应用程序访问您的帐户 support.google.com/accounts/answer/6010255?hl=en
标签: c# email smtpclient