我在 Windows azure 应用程序上有一个 smtp 客户端,该客户端在模拟器上运行良好,但在云实例上引发异常。
异常消息是:
The SMTP server requires a secure connection or the client was not authenticated
The server's response was 5.5.1 authentication required
我通过在命令行中打印它们来确保云上的凭据是正确的,我还禁用了防火墙。
PS:我正在使用 gmail smtp 服务器。
这是我的代码:
private void SetupClient()
{
_emailSetting = new EmailSetting();
_smtpClient = new SmtpClient(_emailSetting.SMTP_Server, _emailSetting.Port);
_smtpClient.EnableSsl = true;
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtpClient.Credentials = new NetworkCredential(_emailSetting.EmailUser, _emailSetting.EmailPass);
}
public void Report(String msg)
{
MailMessage mailMessage;
if (_smtpClient == null)
{
SetupClient();
}
String receivers = String.Join(",", Receivers);
mailMessage = new MailMessage(_emailSetting.EmailUser, receivers, "Error", msg);
_smtpClient.Send(mailMessage);
}