Problem with sending mail

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
I need to send mail using .net
Following code i am using
<pre class="prettyprint public void SendMail()
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("Receive@yahoo.com");
msg.From = new MailAddress("Address@yahoo.in", "Syam");
msg.Subject = "Subject";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "Message";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true; // if msg is in html format
msg.Priority = MailPriority.High;

//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("Address@yahoo.in", "Password");
client.Port = 995;
client.Host = "smtp.mail.yahoo.com";

client.EnableSsl = true;
object userState = msg;
try
{
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
// MessageBox.Show(ex.Message, "Send Mail Error");
}
}[/code]
But i am getting following error

<pre class="prettyprint System.Net.Mail.SmtpException was caught
Message=Failure sending mail.
Source=System
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at SampleApp.About.SendMail() in D:LearnSampleAppSampleAppAbout.aspx.cs:line 80
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(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: System.Net.Sockets.SocketException
Message=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 106.10.167.87:995
Source=System
ErrorCode=10060
NativeErrorCode=10060
StackTrace:
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)
InnerException:
[/code]
Comments are welcome <hr class="sig Happy Coding Syam.S

View the full article
 
Back
Top