问题发送电子邮件中的Web应用程序 [英] Problems sending e-mail in web app
问题描述
我一直在尝试2天,让我的ASP.NET Web表单应用程序发送电子邮件。
我一直在使用Outlook和Gmail的尝试这个。我得到了SMTP信息,无论是从的本教程:
当我尝试使用在例如端口587下面我得到一个错误说:
类型'System.Net.Mail.SmtpException的异常出现在System.dll中,但在用户code没有处理
其他信息:SMTP服务器要求安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要验证
当我尝试使用端口465在下面的例子:
我的应用程序只是挂永远和我的网页永远不会回来我的电子邮件功能,这是在pageLoad的。
几件事情要注意的只是柜面其中之一是搞乱了我:
- 我使用的是标准的VS2013开发环境(运行使用F5调试模式下我的web应用程序)
- 我使用的是相同的电子邮件地址从,到和Gmail的登录凭据)
- 我的ISP没有阻止这些端口。 (康卡斯特有线电视)
-
我还跟谷歌DisplayUnlockCaptcha页面允许访问我的帐户
保护无效SendEmail()
{
字符串EmailAddress的=myemail@gmail.com;
使用(MAILMESSAGE MAILMESSAGE新= MAILMESSAGE(EmailAddress的,EmailAddress的))
{
mailMessage.Subject =这是一个测试电子邮件;
mailMessage.Body =这是一个测试电子邮件,如果你收到请回复。 SmtpClient smtpClient =新SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = TRUE;
smtpClient.Host =smtp.gmail.com;
smtpClient.Port = 587; smtpClient.Credentials =新System.Net.NetworkCredential()
{
用户名= EmailAddress的,
密码=密码
};
smtpClient.UseDefaultCredentials = FALSE;
smtpClient.Send(MAILMESSAGE);
}
}
原来,这是因为Gmail安全设置。
https://www.google.com/settings/security/lesssecureapps
您必须启用不够安全的应用访问。
I have been trying for 2 days to get my ASP.NET webforms application to send an e-mail.
I have tried this using both outlook and gmail. I got the smtp information for both from this tutorial:
When I try using port 587 in the example below I get an error saying: An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
When I try using port 465 in the example below: My application just hangs forever and my page never gets back my email function which is in the PageLoad.
A couple of things to note just incase one of these is messing me up:
- I am using a standard VS2013 dev environment (running my web app in debug mode using F5)
- I am using the same e-mail address for from, to, and gmail login credentials)
- My ISP does not block these ports. (comcast cable)
I even went to the google DisplayUnlockCaptcha page to Allow access to my account
protected void SendEmail() { string EmailAddress = "myemail@gmail.com"; using (MailMessage mailMessage = new MailMessage(EmailAddress, EmailAddress)) { mailMessage.Subject = "This is a test email"; mailMessage.Body = "This is a test email. Please reply if you receive it."; SmtpClient smtpClient = new SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; smtpClient.Host = "smtp.gmail.com"; smtpClient.Port = 587; smtpClient.Credentials = new System.Net.NetworkCredential() { UserName = EmailAddress, Password = "password" }; smtpClient.UseDefaultCredentials = false; smtpClient.Send(mailMessage); } }
It turns out that it is because of a GMail security setting. https://www.google.com/settings/security/lesssecureapps
You have to enable access for less secure apps.
这篇关于问题发送电子邮件中的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!