[英]Unable to send email in asp.net C#
I understand this topic has been well elaborated previously, but I have looked around the Internet for various solutions and nothing has helped so far. 我知道以前已经很好地阐述了这个主题,但是我在互联网上四处寻找各种解决方案,但到目前为止没有任何帮助。
I'm making a web application which at one point is supposed to send an email to the email that the user provided. 我正在制作一个Web应用程序,该应用程序应该在某一时刻向用户提供的电子邮件发送电子邮件。 I'm trying to send it from my gmail account.
我正在尝试从我的Gmail帐户发送它。
I tried the following: 我尝试了以下方法:
public void test()
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("mygmail@gmail.com", "password*"),
EnableSsl = true
};
client.Send("mygmail@gmail.com", "mygmail@gmail.com", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
}
And I'm getting the following error: The server response was: 5.5.1 Authentication Required.
我收到以下错误:
The server response was: 5.5.1 Authentication Required.
In my web.config file I wrote 在我的web.config文件中,我写了
<system.net>
<mailSettings>
<smtp>
<network host="smtp.google.com" password="" userName=""/>
</smtp>
</mailSettings>
</system.net>
But that didn't work. 但这没有用。 I also tried adding the
password*
and the username ( mygmail@gmail.com
) in the web.config instead of the empty strings for userName
and password, but I still got the same error. 我还尝试在web.config中添加
password*
和用户名( mygmail@gmail.com
),而不是userName
和password的空字符串,但是仍然出现相同的错误。
Could anyone please help me out? 有人可以帮我吗? Thank you.
谢谢。
Try setting UseDefaultCredentials to false before specifying your custom credentials. 在指定自定义凭据之前,请尝试将UseDefaultCredentials设置为false。 See c# SmtpClient class not able to send email using gmail
请参阅C#SmtpClient类无法使用gmail发送电子邮件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.