在发送电子邮件后,SMTP是否需要在C#中处理?即使没有附件,是否需要使用C#处理SMTP?
我得到SMTP认证错误,第二次应用程序启动时。我想知道是否需要处理SMTP。第一次在新电脑上不会发生,但如果同一个窗口打开两次,则会出现验证错误。这里是下面的代码。
try{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "FeedBack";
mail.Body = "Text ";
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
SmtpServer.Send(mail);
SmtpServer.Dispose();
}
catch (Exception)
{
Application.Exit();
this.Close();
}
}
好的一般经验法则似乎是,如果一个类提供了一个dispose方法,它有一些需要处理的东西,你应该使用它!我不明白你会如何得到一个认证错误,虽然你有硬编码的证书工作_sometimes _...你能提供实际的错误信息吗? – Bridge
如果你不想手动使用'using(SmtpClient SmtpServer = new SmtpClient(“smtp.gmail.com”)){/ *你的代码在这里* /}'语句。 – dcg
@Bridge实际错误消息'SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应是:5.5.1需要身份验证' – Patrick