我的代码中有什么问题...我想使用yahoo smtp服务器或gmail从我的项目发送邮件 [英] what is the problem in my code ...I want to send mail from my project using yahoo smtp server or gmail

查看:174
本文介绍了我的代码中有什么问题...我想使用yahoo smtp服务器或gmail从我的项目发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 尝试 
{
SmtpClient emailClient = new SmtpClient( smtp.mail.yahoo.com);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential( nasimbahar78@yahoo.com myyahoopassword) ;
emailClient.EnableSsl = true ;
emailClient.Credentials = SMTPUserInfo;
emailClient.Port = 995 ;


System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage( nasimbahar78@yahoo.com nasimbahar78@another.com fire !! 拨打911并告知我的房子着火,我的手机也是);
message.Priority = System.Net.Mail.MailPriority.High;
emailClient.Send(message);
}
catch (例外ee)
{
lblerror.Text = ee.ToString();


}









以下是我的豁免

System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在System.Net.Service.ConnectSocketInternal上的System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)中主动拒绝它188.125.69.59:995 (Boolean connectFailure,Socket s4,Socket s6,Socket& socket,IPAddress& address,ConnectSocketState state,IAsyncResult asyncResult,Int32 timeout,Exception& exception)---内部异常堆栈跟踪结束---在System.Net.ServicePoint处。 System.Net.PooledStream.Activate(Object owningObject,Boolean async,Int32 timeout,GeneralAsyncDelegate asyncCallback)中的GetConnection(PooledStream PooledStream,Object owner,Boolean async,IPAddress& address,Socket& abortSocket,Socket& abortSocket6,Int32 timeout)。 System.Net.ConnectionPool.GetConnection上的Net.PooledStream.Activate(Object owningObject,GeneralAsyncDelegate asyncCallback)(Object owningObject,GeneralAsyncDelegate asyncCallback System.Net.Mail上的System.Net.Mail.SmtpClient.GetConnection()处的System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)处的System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)上的,Int32 creationTimeout) .SmtpClient.Send(MailMessage消息)---内部异常堆栈跟踪结束---在System.Net.Mail.SmtpClient.Send(MailMessage消息)atononcemeeting.Button3_Click(Object sender,EventArgs e)c:\用户\ Mohammad Nasim \Documents\Visual Studio 2010 \WebSites\WebSite4 \ annoncemeeting.aspx.cs:第103行

解决方案

嘿有链接

使用C#中的SMTP发送电子邮件 [ ^ ]

try
      {
          SmtpClient emailClient = new SmtpClient("smtp.mail.yahoo.com");
          System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("nasimbahar78@yahoo.com","myyahoopassword");
          emailClient.EnableSsl = true;
          emailClient.Credentials = SMTPUserInfo;
          emailClient.Port = 995;


          System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("nasimbahar78@yahoo.com", "nasimbahar78@another.com", "fire!!", "Call up 911 and inform my house is on fire and my phone too");
          message.Priority = System.Net.Mail.MailPriority.High;
          emailClient.Send(message);
      }
      catch (Exception ee)
      {
          lblerror.Text = ee.ToString();


      }





below is my excpetion
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 188.125.69.59:995 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- 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(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at annoncemeeting.Button3_Click(Object sender, EventArgs e) in c:\Users\Mohammad Nasim\Documents\Visual Studio 2010\WebSites\WebSite4\annoncemeeting.aspx.cs:line 103

解决方案

Hey there are links
Send Email using SMTP in C#[^]


这篇关于我的代码中有什么问题...我想使用yahoo smtp服务器或gmail从我的项目发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆