答案 0 :(得分:1)
请阅读到最后,您一定可以解决您的问题。
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
...
try
{
SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");
// set smtp-client with basicAuthentication
mySmtpClient.UseDefaultCredentials = false;
System.Net.NetworkCredential basicAuthenticationInfo = new
System.Net.NetworkCredential("youremailid", "youremailpassword");
mySmtpClient.Credentials = basicAuthenticationInfo;
mySmtpClient.EnableSsl = true;
// add from,to mailaddresses
MailAddress from = new MailAddress("youremailid@example.com", "TestFromName");
MailAddress to = new MailAddress("toemailid@example.com", "TestToName");
MailMessage myMail = new System.Net.Mail.MailMessage(from, to);
// add ReplyTo
MailAddress replyto = new MailAddress("reply@example.com");
myMail.ReplyToList.Add(replyTo);
// set subject and encoding
myMail.Subject = "Reset password for [username]";
// set body-message and encoding
myMail.Body = "Please reset password for user [username]";
mySmtpClient.Send(myMail);
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
Google可能会阻止某些未使用现代安全标准的应用或设备的登录尝试。由于这些应用程序和设备更容易被破解,因此屏蔽它们可以使您的帐户更安全。
因此,您必须在Google帐户中启用“不太安全的登录”(或“不太安全的应用程序访问”)。
登录到Google帐户后,转到:
https://www.google.com/settings/security/lesssecureapps
或
https://myaccount.google.com/lesssecureapps
上面的代码来自@NajiMakhoul的链接:) Sending E-Mail using C#,其余信息来自此链接:SMTP Error C#