Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
public void testmail()
{
    var fromAddress = new MailAddress("mr.abzadeh@yahoo.com", null);//"From Name");
    var toAddress = new MailAddress("mr_ab37@yahoo.com", null);//"To Name");
    const string fromPassword = "DivAsiab4000";
    var smtp = new SmtpClient
    {
        //Host = "smtp.gmail.com",
        Host = "smtp.mail.yahoo.com",
        Port = 465,//587,
        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!!";
    //message.Bcc.Add(bcc);
    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 ---
Posted
Updated 15-Nov-13 8:40am
v5
Comments
Ravi Bhavnani 15-Nov-13 12:58pm    
Should you be using port 587?

/ravi
Ron Beyer 15-Nov-13 13:47pm    
Unfortunately 465 is the right port: http://help.yahoo.com/kb/index?page=content&y=PROD_MAIL_ML&locale=en_GB&id=SLN4724
mr.abzadeh 15-Nov-13 14:42pm    
port 587 works. what is the problem with port 465?

The Term port 25 is only available without ssl,tls authentic mode.
and in your case this is because you are
connecting on port 587 EnableSSL //gmail yahoo works well on this
connecting on port 465 is works well while connecting through using outlook or any other application.

These ports are only required if you are using authentication mode open

if you are going to relay directly then you need to connect to port 25 of mx server then send your email with out uid and password.

server 2 server communication always goes through smtp port 25.
 
Share this answer
 
or port 25 - apparently both are common for smtp
 
Share this answer
 
Comments
Ron Beyer 15-Nov-13 13:46pm    
SSL doesn't use port 25, it uses 465 or 587, and he has the port number right: http://help.yahoo.com/kb/index?page=content&y=PROD_MAIL_ML&locale=en_GB&id=SLN4724
mr.abzadeh 15-Nov-13 14:19pm    
Port 25 with Enablessl = false worked, but port 465 didn't work. I examined both Enablessl = true, false, my filewall off
mr.abzadeh 15-Nov-13 14:28pm    
and port 587 worked with Enablessl = true; what is the matter with port 465?
Sharon Freas 15-Nov-13 14:31pm    
I'm glad you got it figured out! Thanks for which ports go with which protocols Ron.
mr.abzadeh 15-Nov-13 14:47pm    
And thanks for your help. Maybe port 465 is closed width the filtering system of the country I live in.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900