Error in Sending Mail Server Actively Refuesed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hardy123
    New Member
    • Feb 2008
    • 3

    #1

    Error in Sending Mail Server Actively Refuesed

    Hi
    I m developing a desktop application using C#
    I m trying to use gmail's smtp sever on port 587 but it is giving me an exception that target machine actively refuesd at 74.125.127.109: 587
    Can any body help me plz...
    My Code is:-
    Code:
              private void Button1_Click(object sender, EventArgs e)
            {
                SmtpClient SmtpServer = new SmtpClient();
                SmtpServer.Credentials = new System.Net.NetworkCredential("mygmailid@gmail.com", "mypassword");
                SmtpServer.Port = 587;
                SmtpServer.Host = "smtp.gmail.com";
                SmtpServer.EnableSsl = true;
                mail = new MailMessage();
                String[] addr = TextBox1.Text.Split(',');
                try 
                {
                    mail.From = new MailAddress("mygmailid@gmail.com", "Developers", System.Text.Encoding.UTF8);
                    mail.Subject = TextBox3.Text;
                    mail.Body = TextBox4.Text;
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    mail.ReplyTo = new MailAddress(TextBox1.Text);
                    SmtpServer.Send(mail);
                }
                catch (Exception ex){
                MessageBox.Show(ex.ToString());
                }
            }
  • pdspider
    New Member
    • Feb 2010
    • 1

    #2
    Hello Hardy

    your code is working fine for me,
    just replaced

    mail.ReplyTo = new MailAddress(Tex tBox1.Text);


    with

    mail.To.Add(new MailAddress(tex tBox1.Text));


    if not for you, please make sure you have entered right credentials

    Thanks

    Comment

    Working...