Hello, guys
I am very new to C#. my background is native C++, I decided to send email from my application, And i think it is easy to create a c# .net dll to do it. I used this code, and I get Error. I do not know how to resolve the error. Can any body help me? or offer a link? I disabled my firewall, but the error exists
thanks in advance
Edit: port=587 worked but=465 did not work. what is the matter with port 465?
public void testmail()
{
var fromAddress = new MailAddress("mr.abzadeh@yahoo.com", null);
var toAddress = new MailAddress("mr_ab37@yahoo.com", null);
const string fromPassword = "DivAsiab4000";
var smtp = new SmtpClient
{
Host = "smtp.mail.yahoo.com",
Port = 465,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 60000 * 2
};
var message = new MailMessage(fromAddress, toAddress);
message.Subject = "This message has come to you thru port 587, firewall on";
message.Body = "Hey now!!";
try
{
smtp.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in testmail(): {0}", ex.ToString());
}
}
and the error is this:
Exception caught in testemail(): System.Net.Mail.SmtpException: Failure
sending mail. ---> System.IO.IOException: Unable to read data from the transport
connection: net_io_connectionclosed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, * Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
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 ---