发送gmail本地主机时出错 [英] error in send gmail localhost
本文介绍了发送gmail本地主机时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用localhost发送gmail
我的代码是这个
i want send gmail with localhost
and my code is this
////my message setting
MailMessage msg = new MailMessage();
msg.From = new MailAddress("XXXXX@gmail.com");
msg.To.Add("YYYY@gmail.com");
msg.Body = "body my mail";
msg.Subject = "my mail subject";
//msg.IsBodyHtml = true;
//msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("XXXXX@gmail.com", "pwd", "smtp.gmail.com");
client.Host = "smtp.gmail.com";
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);
错误是:
SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证.在
了解更多信息
smtp客户端的问题在哪里?
and error is:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
where is problem in smtp client?
推荐答案
问题出在您的身份验证凭据之内. gmail服务器拒绝了您的请求,因为它无法识别凭据,因此您需要使用将被接受的用户ID和密码.我注意到您已经在此处 [ ^ ];尝试它们会发生什么?
[edit]
根据 gmail指南 [
The problem is within your authentication credentials. The gmail server is rejecting your request as it does not recognise the credentials so you need to use a user id and password that will be accepted. I notice that you have already been given some suggestions here[^]; what happens when you try them?
[edit]
According to the gmail guidelines[^], the SMTP server uses port 465 rather than 587 as you have coded.
[/edit]
[edit]
Further testing by me reveals that port 465 times out, but 587 works.
[/edit]
我转到控制面板----管理员工具--smtp设置
并设置我的凭据和....
并开始我的项目
但是也有这个问题
发送邮件失败
i go to controlpanel----administrator toools--smtp setting
and set my credential and ....
and start my project
but a have this problem too
Failure sending Mail
尝试此操作
try this
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );
newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";
////For File Attachment, more file can also be attached
Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );
SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
这篇关于发送gmail本地主机时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文