C# - 通过Gmail或其他方式发送电子邮件?
服务器:VDSC# - 通过Gmail或其他方式发送电子邮件?
操作系统:Windows Server 2008 R2
应用:无
库(应用程序使用DLL):是的,C#
我想通过C#发送邮件使用从我读的,Gmail服务。基本上只是给我自己的测试邮件将是一个开始知道它的作品。如果你不得不问,信息存储在config.json文件中,而不是直接存储在代码中,因此是“AccountRecovery.AccountRecoveryConfig”。
我似乎无法得到它的工作!当使用某些端口时,我得到不同的错误!
端口465 - 使用凭证 错误:
2016-02-05 02:52:33 - Command: ERROR: System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
端口587 - 使用凭证 错误:
2016-02-05 02:55:50 - Command: ERROR: System.Net.Mail.SmtpException: 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
我不知道该怎么做。难道我做错了什么?
public static void SendEmail(string email)
{
MailMessage mail = new MailMessage(AccountRecovery.AccountRecoveryConfig.ServerEmailAddress, email);
SmtpClient client = new SmtpClient();
client.Timeout = 30000;
client.Host = AccountRecovery.AccountRecoveryConfig.HostSMTPServer;
client.Port = AccountRecovery.AccountRecoveryConfig.HostPort;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(AccountRecovery.AccountRecoveryConfig.ServerEmailAddress, AccountRecovery.AccountRecoveryConfig.ServerEmailPassword);
client.EnableSsl = true;
//client.ServicePoint.MaxIdleTime = 1;
mail.Subject = AccountRecovery.AccountRecoveryConfig.EmailSubjectLine;
mail.Body = AccountRecovery.AccountRecoveryConfig.EmailBodyLine;
mail.IsBodyHtml = false;
client.Send(mail);
}
正确的端口是587为谷歌,这个错误:
2016-02-05 02:55:50 - Command: ERROR: System.Net.Mail.SmtpException: 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
你应该给存取安全性较低的应用程序。这里是LINK,你可以在当前登录的Google帐户中使用它。
仍然错误仍然存在。我已启用不太安全的功能... – Marcus101RR
[通过Gmail在.NET中发送电子邮件的可能的副本](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – Filburt