Morcos Adel

Morcos Adel

  • NA
  • 270
  • 42.6k

Somebody help me on sending e-mails please

Jan 10 2009 2:42 PM
i am trying to figure out a way on sending e-mails without using outlook or opening an explorer but i have a little problem which is the program builds ok and without any warnings but an exception with "Failure sending mail" appears on a message box and i don't know why is that....So please any body help me....................!!!!!
thanks in advance......
the code is:

try
            {

                //Create MailMessage Object
                MailMessage email = new MailMessage();

                //Specifying From,Sender & Reply to address
                email.From = new MailAddress("[email protected]");
                email.Sender = new MailAddress("[email protected]");
                email.ReplyTo = new MailAddress("[email protected]);

                // Email
                email.To.Add("[email protected]");
              

                //Subject of email
               email.Subject = "This is a test Mail";

                email.Body = "This is the body of this message";

                //Create an object for SmtpClient class
                SmtpClient mail_client = new SmtpClient();

                //Providing Credentials (Username & password)
                NetworkCredential network_cdr = new NetworkCredential();
                network_cdr.UserName = "xxxxxx";
                network_cdr.Password = "xxxxxxx";

                mail_client.Credentials = network_cdr;

                //Specify the SMTP Port
                mail_client.Port = 25;
               


                //Specify the name/IP address of Host
                mail_client.Host = "smtp.mail.yahoo.com";

                //Uses Secure Sockets Layer(SSL) to encrypt the connection
                mail_client.EnableSsl = true;

                // Send the message
                mail_client.Send(email);

                MessageBox.Show("Email Sent Successfully");
            }
            catch (Exception ex)
            {
                //Exception occured
                MessageBox.Show(ex.Message.ToString());
            }
and the port is opened from the windows firewall...but it still is not working
the exception is
"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"
i can't understand why it doing this so i really need help
somebody please.................
thanks again..


Answers (2)