我正在使用谷歌smtp发送电子邮件。代码在我的本地计算机中正常运行。但在生产服务器上,我收到错误消息为SendEmail SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
了解更多信息我试过这个, client.UseDefaultCredentials = true; 将其设置为false但不起作用。
答案 0 :(得分:0)
尝试使用此代码发送Google邮件
MailMessage oMail = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string FromMailID = "yourgmailid@gmail.com";
string UserName = "GmailUsername";
string Password = "GmailPassword";
MailAddress fromAddress = new MailAddress(FromMailID);
if (FilePath != "")//If attached file otherwise comment
{
Attachment PDFfile = new Attachment(FilePath);
oMail.Attachments.Add(PDFfile);
}
oMail.From = fromAddress;
oMail.To.Add(ToMailID);
oMail.Subject = Subject;
oMail.IsBodyHtml = true;
oMail.Body = Mailcontent.ToString();
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 25;//localhost
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential(UserName, Password);
smtpClient.Send(oMail);