在asp.net中发送邮件失败 [英] Failure sending mail in asp.net
本文介绍了在asp.net中发送邮件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
这里我面临发送邮件的问题,当我使用这个脚本的gmail,工作正常,但当我尝试我的邮件服务器显示错误但在我的邮件服务器工作正常,直接发送
这里我的脚本
使用(MailMessage mm = new MailMessage(txtemail.Text , mailme@myserver.com))
{
mm.Subject = 来自网站的消息名称: + txtname.Text;
mm.Body = NAME: + txtname.Text + \ n + 地址: + txtaddr.Text + \ n + 电话: + txtphone.Text + \ n + E-mailID: + txtemail.Text + \ n + 注意: + txtnote.Text + \\\
跨度>;
mm.IsBodyHtml = false ;
SmtpClient smtp = new SmtpClient();
smtp.Host = mail.myserver.com;
smtp.EnableSsl = false ;
NetworkCredential NetworkCred = new NetworkCredential( mailme @ myserver.com, pwd);
smtp.UseDefaultCredentials = true ;
smtp.Credentials = NetworkCred;
smtp.Port = 26 ;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), alert, alert('电子邮件已成功发送');, true );
txtname.Text = ; txtaddr.Text = ; txtemail.Text = ; txtnote.Text = ; txtphone.Text = ;
}
显示发送邮件失败等错误。
如何解决这个问题
谢谢..
解决方案
您可以使用下面给出的示例代码。它是一个工作的。
使用 System.Net.Mail;
string MailSrvr = yourserver.com跨度>;
SmtpClient mclient = new SmtpClient();
MailMessage mailmsg = new MailMessage();
mclient.Host = MailSrvr;
MailAddress frmadd,toadd,tocc,tobcc;
frmadd = new MailAddress( fromaddress, 来自发件人名称);
mailmsg.From = frmadd;
mailmsg.IsBodyHtml = true ;
mailmsg.Priority = MailPriority.Normal;
mailmsg.Subject = 测试主题;
strline = 邮件正文;
mailmsg.Body = strline;
toadd = new MailAddress( toaddress, To Receiver Name);
mailmsg.To.Add(toadd);
tocc = new MailAddress( ccaddress, CC);
mailmsg.CC.Add(tocc);
tobcc = new MailAddress( bccaddress, BCC);
mailmsg.Bcc.Add(tobcc);
mclient.Send(mailmsg);
mailmsg.Dispose();
问候,
Fathima Nishana Jabbar。
下面是我用于发送电子邮件的代码我相信它会起作用
下面是你需要使用的库文件为此目的
System.Net.Mail;
,然后转到配置中的web.config中的代码部分
定义主机,即您要从中发送消息。
每个站点都有端口号我以gmail为例,它的端口号是587
< system.net >
< mailSettings >
< smtp < span class =code-attribute> from = emailid >
< network host = smtp@gmail.com port = 587 userName = 用户名 密码 = 密码 / >
< / smtp >
< / mailSettings < span class =code-keyword>>
< / system.net >
以下是s的实际代码最终邮件
string toemail =email address;
string message =这是一封示例电子邮件;
MailMessage mail = new MailMessage();
mail.To.Add(toemail);
mail.Subject =邮件样本;
mail.Body = message;
mail.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Send(mail);
Hi Prasanna,
你的ISP阻止端口25?您是否尝试使用端口587?或者,请参阅这篇文章 http ://dotnet4hosting.asphostportal.com/post/ASPNET-4-Hosting-ASPHostPortal-How-to-Send-Email-with-Gmail-SMTP.aspx [ ^ ]。
希望这有帮助
Hi All
Here i'm facing prob with sent mail, when i use this script for gmail, working fine but when i try my mail server showing error but in my mail server working fine as sent directly
Here My Script
using (MailMessage mm = new MailMessage(txtemail.Text, "mailme@myserver.com"))
{
mm.Subject = "Message From Website NAME : "+txtname.Text;
mm.Body = "NAME : "+txtname.Text + "\n"+"Address : "+ txtaddr.Text + "\n" +"Phone : "+ txtphone.Text + "\n" +"E-mailID : "+ txtemail.Text + "\n" +"Note : "+ txtnote.Text + "\n";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = " mail.myserver.com";
smtp.EnableSsl = false;
NetworkCredential NetworkCred = new NetworkCredential("mailme@myserver.com", "pwd");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 26;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('E-Mail Sent Successfully');", true);
txtname.Text = ""; txtaddr.Text = ""; txtemail.Text = ""; txtnote.Text = ""; txtphone.Text = "";
}
showing error like "Failure sending mail."
how to slove this
thanks..
解决方案
Hi,
You can use the sample code given below. Its a working one.
using System.Net.Mail; string MailSrvr = "yourserver.com"; SmtpClient mclient = new SmtpClient(); MailMessage mailmsg = new MailMessage(); mclient.Host = MailSrvr; MailAddress frmadd, toadd, tocc, tobcc; frmadd = new MailAddress("fromaddress", "From Sender Name"); mailmsg.From = frmadd; mailmsg.IsBodyHtml = true; mailmsg.Priority = MailPriority.Normal; mailmsg.Subject = "Test Subject"; strline = "body of the mail"; mailmsg.Body = strline; toadd = new MailAddress("toaddress", "To Receiver Name"); mailmsg.To.Add(toadd); tocc = new MailAddress("ccaddress", "CC"); mailmsg.CC.Add(tocc); tobcc = new MailAddress("bccaddress", "BCC"); mailmsg.Bcc.Add(tobcc ); mclient.Send(mailmsg); mailmsg.Dispose();
Regards,
Fathima Nishana Jabbar.
below is the code I have used for emailing purpose I'am sure it will work
Below is the library file you need to use for this purpose
System.Net.Mail;
before going to code in web.config under configuration section
define host i.e. from which you want to send the message.
every site will have port number i have taken gmail as an example its port number is 587
<system.net> <mailSettings> <smtp from="emailid"> <network host="smtp@gmail.com" port="587" userName="username" password="password" /> </smtp> </mailSettings> </system.net>
below is the actual code to send mail
string toemail = "email address"; string message = "Hi this is a sample email"; MailMessage mail = new MailMessage(); mail.To.Add(toemail); mail.Subject = "Sample mail"; mail.Body = message; mail.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.EnableSsl = true; smtp.Send(mail);
Hi Prasanna,
Does your ISP block port 25? Have you try to use port 587? Or, please refer to this post http://dotnet4hosting.asphostportal.com/post/ASPNET-4-Hosting-ASPHostPortal-How-to-Send-Email-with-Gmail-SMTP.aspx[^].
Hope this helps
这篇关于在asp.net中发送邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文