在ASP.NET中使用gmail发送电子邮件时出现错误 [英] error when sending email using gmail in ASP.NET
本文介绍了在ASP.NET中使用gmail发送电子邮件时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用gmail发送电子邮件,以下是我的代码
I am trying to send email using gmail, below is my code
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("from@gmail.com", "From Me");
MailAddress toAddress = new MailAddress("to@gmail.com", "To You");
message.From = fromAddress;
message.To.Add(toAddress);
message.Subject = "Testing!";
message.Body = "This is the body of a sample message";
smtpClient.Host = "smtp.gmail.com";
smtpClient.Credentials = new System.Net.NetworkCredential("username", "password");
smtpClient.EnableSsl = true;
smtpClient.Port = 587;
smtpClient.Send(message);
我收到此错误"SMTP服务器需要安全连接或客户端未通过身份验证.服务器响应为:5.5.1需要身份验证."
密码和用户名都是正确的,我尝试了很多事情,但是不起作用:(
请任何人帮助我
谢谢
I am getting this error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."
Password and username is all correct, i tried lot of things but not working :(
Plz anyone help me
Thanks
推荐答案
希望此 [ ^ ]可能会为您提供帮助.
Hope this[^] might help you.
在这里,
使用ASP.net通过Gmail帐户(Gmail SMTP服务器帐户)发送电子邮件 [ ^ ]
如何通过VB.NET或C#从GMAIL帐户发送邮件. Windows编程,具有一定的自定义功能 [ ^ ]
Here we go,
Sending E-mail using ASP.net through Gmail account (Gmail SMTP Server account)[^]
How to Send Mails from your GMAIL Account through VB.NET or C#. Windows Programming, with a Bit of Customization[^]
您没有在SmtpClient()对象中指定Smtpclient名称.
只需在新SmtpClient()的声明上方添加此行;对象.
字符串服务器="smtp.gmail.com";
并将字符串参数传递给smtpclient对象,如下所示:
SmtpClient smtpClient =新的SmtpClient(服务器);
而不是"SmtpClient smtpClient = new SmtpClient();"
这将起作用..:)
Hi,
You did not specified Smtpclient name in your SmtpClient() object.
Just add this line above the declaration of new SmtpClient(); object.
String server= "smtp.gmail.com";
and pass the string parameter to smtpclient object like this :
SmtpClient smtpClient = new SmtpClient(server);
instead of "SmtpClient smtpClient = new SmtpClient();"
this will work.. :)
这篇关于在ASP.NET中使用gmail发送电子邮件时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文