如何通过ASP.net C#发送邮件 [英] How to send Mail through ASP.net C#
本文介绍了如何通过ASP.net C#发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我用于发送电子邮件的代码
通过ASP.NET和C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Net.Mail; using System.Configuration; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void bt_sendMail_Click(object sender, EventArgs e) { SendMail(tb_GmailAccount.Text, tb_GmailPassword.Text, tb_RecieverEmail.Text, tb_Subject.Text, tb_Message.Text); } public void SendMail(string gMailAccount, string password, string to, string subject, string message) { try { MailMessage msg = new MailMessage(); msg.From = new MailAddress(gMailAccount); msg.To.Add(new MailAddress(to)); msg.Subject = subject; msg.Body = message; msg.IsBodyHtml = true; msg.Priority = MailPriority.Normal; var client = new SmtpClient("smtp.gmail.com", 587) { UseDefaultCredentials = false, Credentials = new NetworkCredential(gMailAccount, password), EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network }; client.Send(msg); } catch (Exception ex) { string s = ex.Message; ; } } }
但是由于SMTP EXCEPTION CAUGHT导致异常..无法发送.
请引导我问题出在哪里
解决方案
请参阅此
发送邮件失败 [使用 System.Net.Mail; 公共 字符串 ord,正文; MailMessage oMail = 新 MailMessage(); SmtpClient oSmtp = 新 SmtpClient(" ,尝试 { oMail.To.Add(b@b.com); oMail.From = 新 MailAddress(" ); oMail.Subject = " ; body = " ; 身体+ = " true ; oSmtp.UseDefaultCredentials = false ; oSmtp.Credentials = 新 System.Net.NetworkCredential(" , 密码"); oSmtp.EnableSsl = true ; oSmtp.Send(oMail); } 捕获 {}
following is the Code I am using to Send Email
through ASP.NET and C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Net.Mail; using System.Configuration; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void bt_sendMail_Click(object sender, EventArgs e) { SendMail(tb_GmailAccount.Text, tb_GmailPassword.Text, tb_RecieverEmail.Text, tb_Subject.Text, tb_Message.Text); } public void SendMail(string gMailAccount, string password, string to, string subject, string message) { try { MailMessage msg = new MailMessage(); msg.From = new MailAddress(gMailAccount); msg.To.Add(new MailAddress(to)); msg.Subject = subject; msg.Body = message; msg.IsBodyHtml = true; msg.Priority = MailPriority.Normal; var client = new SmtpClient("smtp.gmail.com", 587) { UseDefaultCredentials = false, Credentials = new NetworkCredential(gMailAccount, password), EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network }; client.Send(msg); } catch (Exception ex) { string s = ex.Message; ; } } }
But getting Exception as SMTP EXCEPTION CAUGHT ..Failure to send.
Please Guide me where is the Problem
解决方案
refer this
Failure sending mail[^]
Hope This Helps..
using System.Net; using System.Net.Mail; public string ord, body; MailMessage oMail = new MailMessage(); SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 587); try { oMail.To.Add(b@b.com); oMail.From = new MailAddress("a@a.com"); oMail.Subject = "Subject"; body = "Hello, <br />"; body += "How are you"; oMail.Body = body; oMail.IsBodyHtml = true; oSmtp.UseDefaultCredentials = false; oSmtp.Credentials = new System.Net.NetworkCredential("a@a.com", "password"); oSmtp.EnableSsl = true; oSmtp.Send(oMail); } catch { }
这篇关于如何通过ASP.net C#发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文