我无法使用Gmail设置发送电子邮件。我已经尝试client.Host =“本地主机”它的工作,但不是在client.Host =“smtp.gmail.com”..请帮助我的家伙..我需要使用client.Host =“smtp.gmail.com”.. ..在这里感谢使用Gmail设置发送电子邮件时出现问题
是我的C#代码:
string from = "[email protected]"; //Replace this with your own correct Gmail Address
string to = "[email protected]"; //Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to); mail.From = new
MailAddress(from, "One Ghost" ,System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ; mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(); //Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "iseedeadpoeple");
client.Port = 587; // Gmail works on this port client.Host ="smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
} HttpContext.Current.Response.Write(errorMessage
);
} // end try
这里的错误:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
大部分谢谢你们!
http://archive.msdn.microsoft.com/CSharpGmail – Peter 2011-04-06 11:55:04
我很高兴你考虑了我对你最后一个问题的评论,并且花时间写下你的问题:-) – 2011-04-06 14:55:20