问题发送电子邮件 [英] Problem with sending email
问题描述
SMTP的发送方法总是抛出异常。该消息是:发送邮件失败
下面是我的code:
毫米MAILMESSAGE新= MAILMESSAGE();
mm.To.Add(Yuvraj.dhot@xxxxx.co.in);mm.From =新的MailAddress(Kumar.Chaudhari@xxxxx.co.in);
mm.Subject =蚂蚁主题;
mm.Body =身体茶MEssag这里;SmtpClient SS =新SmtpClient(localhost的);ss.EnableSsl = FALSE;尝试
{
** ss.Send(毫米); **
Result.Text =消息发送;
Result.ForeColor = System.Drawing.Color.Green;
}
赶上(SmtpException前)
{
Result.Text =消息发送失败:\\ n \\ n+ ex.Message;
Result.ForeColor = System.Drawing.Color.Red;
}
我使用也试过
ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
现在它不抛出任何异常,它执行罚款,但接收机没有接收任何邮件在他的收件箱。
我该如何解决这个问题?
编辑 - 这是堆栈跟踪即时得到
消息=发送邮件失败。来源=系统堆栈跟踪:在System.Net.Mail.SmtpClient.Send
在WebApplication1._Default.Page_Load(对象发件人,EventArgs e)在D(消息MAILMESSAGE):\\ Emcure-
库马尔\\工作\\不使用\\ WebApplication1 \\ WebApplication1 \\ Default.aspx.cs:第30行的InnerException:
System.Net.WebException消息=无法连接到远程服务器源=系统堆栈跟踪: -
在System.Net.ServicePoint.GetConnection(PooledStream PooledStream,对象所有者,布尔异步,
ip地址和放大器;地址,插座及放大器; abortSocket,插座及放大器; abortSocket6,的Int32超时)在
System.Net.PooledStream.Activate(对象owningObject,布尔异步,的Int32超时,
GeneralAsyncDelegate的AsyncCallback)在System.Net.PooledStream.Activate(对象owningObject,
GeneralAsyncDelegate的AsyncCallback)在System.Net.ConnectionPool.GetConnection(对象owningObject,
GeneralAsyncDelegate的AsyncCallback,的Int32 creationTimeout)
在System.Net.Mail.SmtpConnection.GetConnection(字符串主机,端口的Int32)的
System.Net.Mail.SmtpTransport.GetConnection(字符串主机,端口的Int32)的
System.Net.Mail.SmtpClient.GetConnection()在System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)
的InnerException:System.Net.Sockets.SocketException消息=无法连接,因为进行
目标机器积极地拒绝它127.0.0.1:25来源=系统错误code = 10061 NativeError code = 10061
您execption应包含比发送邮件失败的详细信息。
有关这个链接调试找对方法SmtpClient.Send抛出产生的异常详细信息 - >的 SmtpClient.Send方法
这code作品有smtp.google.com
毫米MAILMESSAGE新= MAILMESSAGE();
mm.From =新的MailAddress(XX);
mm.To.Add(XX);
mm.Subject =蚂蚁主题;
mm.Body =身体茶MEssag这里; SmtpClient SS =新SmtpClient();
ss.Host =smtp.gmail.com;
ss.Port = 587;
ss.EnableSsl = TRUE; ss.Credentials =新System.Net.NetworkCredential(XX,XX);
尝试
{
ss.Send(毫米);
Label1.Text =消息发送;
Label1.ForeColor = System.Drawing.Color.Green;
}
赶上(SmtpException前)
{
Label1.Text =消息发送失败:\\ n \\ n+ ex.Message;
Label1.ForeColor = System.Drawing.Color.Red;
}
谷歌需要启用SSL和端口587是传出端口。你需要一个谷歌帐户,以及凭据。
没有错,你的code - 这是最有可能您的服务器或防火墙
The send method of SMTP is always throwing an exception. The message is : Failure sending mail
Here is my code:
MailMessage mm = new MailMessage();
mm.To.Add("Yuvraj.dhot@xxxxx.co.in");
mm.From = new MailAddress("Kumar.Chaudhari@xxxxx.co.in");
mm.Subject = "Ant Subject";
mm.Body = "Body Cha MEssag here ";
SmtpClient ss = new SmtpClient("localhost");
ss.EnableSsl = false;
try
{
**ss.Send(mm);**
Result.Text = "Message Sent";
Result.ForeColor = System.Drawing.Color.Green;
}
catch (SmtpException ex)
{
Result.Text = "Message Not Sent : \n\n " + ex.Message;
Result.ForeColor = System.Drawing.Color.Red;
}
I also tried using
ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
Now it doesn't throw any exception, it executes fine but receiver does not receive any mail in his inbox.
How can I fix this?
Edit - This is the stack trace im getting
Message=Failure sending mail. Source=System StackTrace: at System.Net.Mail.SmtpClient.Send
(MailMessage message) at WebApplication1._Default.Page_Load(Object sender, EventArgs e) in D:\Emcure-
Kumar\Work\Not in Use\WebApplication1\WebApplication1\Default.aspx.cs:line 30 InnerException:
System.Net.WebException Message=Unable to connect to the remote server Source=System StackTrace: –
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async,
IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout,
GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject,
GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject,
GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at
System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)
InnerException: System.Net.Sockets.SocketException Message=No connection could be made because the
target machine actively refused it 127.0.0.1:25 Source=System ErrorCode=10061 NativeErrorCode=10061
Your execption should contain more info than "Failure sending mail"
For debugging look at this link for details on the Exeptions thrown by SmtpClient.Send Method - > SmtpClient.Send Method
This code works with "smtp.google.com"
MailMessage mm = new MailMessage();
mm.From = new MailAddress("xx");
mm.To.Add("xx");
mm.Subject = "Ant Subject";
mm.Body = "Body Cha MEssag here ";
SmtpClient ss = new SmtpClient();
ss.Host="smtp.gmail.com";
ss.Port = 587;
ss.EnableSsl = true;
ss.Credentials = new System.Net.NetworkCredential("xx", "xx");
try
{
ss.Send(mm);
Label1.Text = "Message Sent";
Label1.ForeColor = System.Drawing.Color.Green;
}
catch (SmtpException ex)
{
Label1.Text = "Message Not Sent : \n\n " + ex.Message;
Label1.ForeColor = System.Drawing.Color.Red;
}
Google requires SSL enabled and port 587 to be the outgoing port. You need a google account as well for credentials.
Nothing wrong with your code - it's most likely your server or firewall
这篇关于问题发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!