public void sendit()
{
try
{
SmtpClient mySmtpClient = new SmtpClient("out.bezeqint.net");
// set smtp-client with basicAuthentication
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Port = 110;
mySmtpClient.EnableSsl = true;
System.Net.NetworkCredential basicAuthenticationInfo = new
System.Net.NetworkCredential("myuser", "mypass");
mySmtpClient.Credentials = basicAuthenticationInfo;
// add from,to mailaddresses
MailAddress from = new MailAddress("test@bezeqint.net", "TestFromName");
MailAddress to = new MailAddress("test@bezeqint.net", "TestToName1");
MailMessage myMail = new System.Net.Mail.MailMessage(from, to);
// add ReplyTo
MailAddress replyto = new MailAddress("test@bezeqint.net");
myMail.ReplyToList.Add(replyto);
// set subject and encoding
myMail.Subject = "Test message";
myMail.SubjectEncoding = System.Text.Encoding.UTF8;
// set body-message and encoding
myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
myMail.BodyEncoding = System.Text.Encoding.UTF8;
// text or html
myMail.IsBodyHtml = true;
mySmtpClient.Send(myMail);
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
例外情况发生在第一次捕获。
"Failure sending mail."
StackTrace
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Emails\SendEmail.cs:line 150
第150行
mySmtpClient.Send(myMail);
客户端bezeqint至少是用于获取/下载我正在使用openpop的电子邮件的pop3。但是发送电子邮件我正在使用smtp并获得例外。
在form1的顶部
using System.Net.Mail;
有关例外的更多信息:
[System.Net.WebException] = {“无法连接到远程服务器”}
和StackTrace
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, 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)
和InnerException
InnerException = {“连接尝试失败,因为连接方在一段时间后没有正确响应或建立的连接失败,因为连接的主机无法响应192.115.187.185:110”}