当我向我的Gmail帐户发送邮件时,它会显示以下错误。
SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.7.1需要验证... 我正在使用的代码在
之下MailMessage m = new MailMessage();
SmtpClient sc = new SmtpClient();
try
{
m.From = new MailAddress("me@gmail.com");
m.To.Add("me@gmail.com");
m.Subject = "This is a Test Mail";
m.IsBodyHtml = true;
m.Body = "test gmail";
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.Credentials = new System.Net.NetworkCredential("me@gmail.com", "passward");
sc.UseDefaultCredentials = true;
sc.EnableSsl = true;
sc.Send(m);
Response.Write("Email Send successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
答案 0 :(得分:1)
刚试过你的代码,不得不摆弄几件东西,但却被发送了。有趣,因为我之前使用Gmail smtp(几年前)完成了这项工作。但看起来他们现在正在验证使用他们平台的应用程序。
使用您注册的其他smtp服务器,或使用您自己的服务器。 (必须有一个在线可用的测试??)。很确定sendgrid可以免费试用。
答案 1 :(得分:0)
using System.Net;
using System.Net.Mail;
string smtpAddress = "smtp.mail.yahoo.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "email@yahoo.com";
string password = "abcdefg";
string emailTo = "someone@domain.com";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
请尝试这个应该适合你 谢谢