发送电子邮件时出错 [英] error while sending email

查看:149
本文介绍了发送电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误消息:

Error message:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 67.228.109.8:26 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) 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(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) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at html_mail.Page_Load(Object sender, EventArgs e)



我的代码如下...



My code is as follows...

//web .config code

 <system.net>
    <mailSettings>
      <smtp from="info@enefinder.com" >
        <network host="mail.enefinder.com" port="26" userName="username" password="password"/>
      </smtp>
    </mailSettings>
  </system.net>

//.........

MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("mail.enefinder.com");
            mail.From = new MailAddress("info@enefinder.com");
            mail.To.Add("abc@yahoo.com");
            mail.Subject = "enefinder";
            mail.Body = "mail with attachment";

            //System.Net.Mail.Attachment attachment;
            //attachment = new System.Net.Mail.Attachment("you attachment file");
            //mail.Attachments.Add(attachment);

            SmtpServer.Port = 26;
            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
            Response.Write("mail send");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }





Thanks in advance!

推荐答案

好,您使用了邮件服务器,并收到一条错误消息,告诉您该服务器未响应.您需要告诉我们的是,为什么您不相信该错误就表示它的确切含义.您是否检查了服务器上的防火墙?
Well, you used a mail server and got an error message telling you that this server did not respond. What you need to tell us, is why you don''t believe the error to mean exactly what it says. Did you check your firewall on your server ?


.net新代码中的任何错误
is anything wrong in code im new to .net


System.Net.Mail.MailMessage Email =新的System.Net.Mail.MailMessage(fromEmail,toEmail);
Email.Subject =测试主题";
Email.Body =这是一个测试";
System.Net.Mail.SmtpClient mailClient =新的System.Net.Mail.SmtpClient();
System.Net.NetworkCredential basicAuthenticationInfo =新System.Net.NetworkCredential(FromEmailAdd,PassWord);
mailClient.Host = smtpserver;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Send(Email);
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage(fromEmail, toEmail);
Email.Subject = "test subject";
Email.Body = "this is a test";
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(FromEmailAdd, PassWord);
mailClient.Host = smtpserver;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Send(Email);


这篇关于发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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