views:

379

answers:

4

Hi, I have my code here, it works fine from my home, where my user is administrator, and I am connected to internet via a cable network. But, problem is when I try this code from my work place, it does not work. Shows error: "unable to connect to the remote server" From a different machine in the same network: "A socket operation was attempted to an unreachable network 209.xxx.xx.52:25"

I checked with our network admin, and he assured me that all the mail ports are open [25,110, and other ports for gmail].

Then, I logged in with administrative privilege, there was a little improvement, it did not show any error, but the actual email was never received.

Please note that, the code was tested from development environment, visual studio 2005 and 2008.

Any suggestion will be much appreciated. Thanks in advance

 try
    {
        MailMessage mail_message = new MailMessage("[email protected]", txtToEmail.Text, txtSubject.Text, txtBody.Text);
        SmtpClient mail_client = new SmtpClient("SMTP.y7mail.com");
        NetworkCredential Authentic = new NetworkCredential("[email protected]", "xxxxx");
        mail_client.UseDefaultCredentials = true;
        mail_client.Credentials = Authentic;
        mail_message.IsBodyHtml = true;
        mail_message.Priority = MailPriority.High;
        try
        {
            mail_client.Send(mail_message);
            lblStatus.Text = "Mail Sent Successfully";
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message);
            lblStatus.Text = "Mail Sending Failed\r\n" + ex.Message;
        }
    }
    catch (Exception ex)
    {
        lblStatus.Text = "Mail Sending Failed\r\n" + ex.Message;
    }
+1  A: 

Try setting UseDefaultCredentials to false.

James
A: 

Also try switching SSL on for y7mail

mail_client.EnableSSL = true;

Source - http://help.yahoo.com/l/au/yahoo7/edit/registration/registration-488246.html

CResults
A: 

Here is some sample code that works for me and talks to a gmail server

private void SendEmail(string from, string to, string subject, string body)
    {
      MailMessage mail = new MailMessage(new MailAddress(from), new MailAddress(to));

      mail.Subject = subject;
      mail.Body = body; 

      SmtpClient smtpMail = new SmtpClient("smtp.gmail.com");
      smtpMail.Port = 587;
      smtpMail.EnableSsl = true;
      smtpMail.Credentials = new NetworkCredential("[email protected]", "xxx");
      // and then send the mail
      smtpMail.Send(mail);
    }
Gray Area
Thanks. It did work for me, too. Not only for gmail, but for y7mail too! Is there any specialty about this port 587?
Kaysar
Main part of the code that made it work:MailMessage mail_message = new MailMessage("[email protected]", txtToEmail.Text, txtSubject.Text, txtMailBody.Text); SmtpClient mail_client = new SmtpClient("SMTP.y7mail.com", 587); NetworkCredential Authentic = new NetworkCredential("[email protected]", "xxx"); mail_client.UseDefaultCredentials = true; mail_client.Credentials = Authentic;
Kaysar
Glad it worked out. Port 587b is the standard port for email submission with ESMTP(RFC2476).
Gray Area
A: 

Yahoo mail server requires SSL.

rtpHarry