无法在 C# 中发送邮件:system.dll 中的错误
Can't send mails in C# : Error in system.dll
我正在尝试此代码,以便使用他输入的邮件将他的密码发送给某个用户。
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("fzc.solutions@gmail.com", "********");
//de qui, a qui, objet, sujet
MailMessage mm = new MailMessage("bluepenlabs.aux@gmail.com", "fzc.solutions@gmail.com", "test", "test");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);
这是错误:
Une exception non gérée du type 'System.Net.Mail.SmtpException' s'est
produite dans System.dll
Informations supplémentaires : Le serveur SMTP requiert une connexion
sécurisée ou le client n'était pas authentifié. La réponse du serveur
était : 5.5.1 Authentication Required. Learn more at
我会在这里翻译:
An unhandled exception of type 'System.Net.Mail.SmtpException'
occurred in System.dll
Additional information: The SMTP server requires a secure connection
or the client was not authenticated. The server response was: 5.5.1
Authentication Required. Learn more at
虽然我尝试使用两个不同的 gmail 帐户,同样的错误,但我确定密码是正确的。当我将端口更改为 465 时,出现此错误:
An unhandled exception of type 'System.Net.Mail.SmtpException'
occurred in System.dll
Additional Information: The operation timeout expired.
我必须将超时设置为 10000、20000 甚至 100000,但仍然没有!
请帮忙谢谢!
请注意 gmail "locks" 如果您尝试了几次都没有成功,请使用该帐户。我用我的私人 gmail 帐户尝试了不同的代码示例,但一切都失败了。当我从 GMail 了解要求后,我创建了一个新的 gmail 帐户并获得了相同的代码。
该代码与您的代码非常相似,但 NetworkCredentials 除外。这是来自另一个 Whosebug 问题的代码(由于多次尝试,用我的私人帐户尝试但没有成功):Send email using System.Net.Mail through gmail
//Code
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("***@gmail.com");
SmtpClient smtp = new SmtpClient();
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(mail.From.Address, "****");
smtp.Host = "smtp.gmail.com";
//recipient
mail.To.Add(new MailAddress("***@gmail.com"));
mail.IsBodyHtml = true;
string st = "Test";
mail.Body = st;
smtp.Send(mail);
Gmail 帐户默认禁用 低安全应用访问权限。
可以通过在安全选项下授予对电子邮件帐户中 低安全应用程序 的访问权限来修复此错误。
我正在尝试此代码,以便使用他输入的邮件将他的密码发送给某个用户。
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("fzc.solutions@gmail.com", "********");
//de qui, a qui, objet, sujet
MailMessage mm = new MailMessage("bluepenlabs.aux@gmail.com", "fzc.solutions@gmail.com", "test", "test");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);
这是错误:
Une exception non gérée du type 'System.Net.Mail.SmtpException' s'est produite dans System.dll
Informations supplémentaires : Le serveur SMTP requiert une connexion sécurisée ou le client n'était pas authentifié. La réponse du serveur était : 5.5.1 Authentication Required. Learn more at
我会在这里翻译:
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
虽然我尝试使用两个不同的 gmail 帐户,同样的错误,但我确定密码是正确的。当我将端口更改为 465 时,出现此错误:
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll Additional Information: The operation timeout expired.
我必须将超时设置为 10000、20000 甚至 100000,但仍然没有!
请帮忙谢谢!
请注意 gmail "locks" 如果您尝试了几次都没有成功,请使用该帐户。我用我的私人 gmail 帐户尝试了不同的代码示例,但一切都失败了。当我从 GMail 了解要求后,我创建了一个新的 gmail 帐户并获得了相同的代码。
该代码与您的代码非常相似,但 NetworkCredentials 除外。这是来自另一个 Whosebug 问题的代码(由于多次尝试,用我的私人帐户尝试但没有成功):Send email using System.Net.Mail through gmail
//Code
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("***@gmail.com");
SmtpClient smtp = new SmtpClient();
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(mail.From.Address, "****");
smtp.Host = "smtp.gmail.com";
//recipient
mail.To.Add(new MailAddress("***@gmail.com"));
mail.IsBodyHtml = true;
string st = "Test";
mail.Body = st;
smtp.Send(mail);
Gmail 帐户默认禁用 低安全应用访问权限。 可以通过在安全选项下授予对电子邮件帐户中 低安全应用程序 的访问权限来修复此错误。