我在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
我确保云端的凭据在命令行中打印正确,我也禁用了防火墙。
P.S:我正在使用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);
}
答案 0 :(得分:1)
答案 1 :(得分:0)
解决此问题的一种方法是在您的Azure VM上使用RDP并从那里登录您的Gmail帐户。 Google会要求您确认自己的帐户,因为这是一个“奇怪”的位置。 经过验证,您的电子邮件将正常运行。