ASP.NET发送邮件 [英] ASP.NET Send Email
问题描述
我想,当用户点击一个联系我们页面,但出于某种原因,它不工作提交发送电子邮件,我究竟做错了什么? (PS电子邮件和放大器;密码从这个code段省略了,但包含在实际的解决方案。
感谢
code在web.config中:
< system.net>
< mailSettings>
<从=order@test.com&GT SMTP;
<网络主机=smtp.gmail.com
的userName =//我的电子邮件
密码=//删除密码隐私的原因
的DefaultCredentials =假
端口=456
enableSsl =真/>
< / SMTP>
< / mailSettings>
code在asp.net联系方式:
保护无效btnSubmit_Click(对象发件人,EventArgs的发送)
{
邮件MAILMESSAGE新= MAILMESSAGE();
mail.To.Add(新MailAddress(test@gmail.com));
mail.Subject =测试;
mail.Body = + txtName.text + txtComment.text信息被发送;
SmtpClient SMTP =新SmtpClient();
smtp.SendAsync(邮件,NULL);
}
Gmail的使用端口 465
,而不是 456
对于SSL SMTP。从这里:
发送邮件(SMTP)服务器 - 需要TLS1或SSL:smtp.gmail.com
使用验证:是
端口为TLS / STARTTLS:587
SSL的端口:465
块引用>I am trying to send a email when user clicks submit in a contact us page but for some reason its not working, what am I doing wrong? (PS email & password was omited from this code snippet but included in actual solution.
Thanks
Code in web.config:
<system.net> <mailSettings> <smtp from="order@test.com"> <network host="smtp.gmail.com" userName="" //my email password="" //password deleted for privacy reasons defaultCredentials="false" port="456" enableSsl="true" /> </smtp> </mailSettings>
code in asp.net contact form:
protected void btnSubmit_Click(object sender, EventArgs e) { MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress("test@gmail.com")); mail.Subject = "Test"; mail.Body = "Message was sent from" + txtName.text + txtComment.text; SmtpClient smtp = new SmtpClient(); smtp.SendAsync(mail, null); }
解决方案Gmails uses port
465
, not456
for SSL SMTP. From here:Outgoing Mail (SMTP) Server - requires TLS1 or SSL: smtp.gmail.com
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
这篇关于ASP.NET发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!