Server error when trying to send automated email

Discussion in 'ASP.NET 2.0' started by jackharper, Jun 26, 2007.

  1. Hi.

    I am running into an error when I try to send an email through ASP.NET.

    The error is saying 'A socket operation was attempted to an unreachable host'

    You can view and reproduce this error at http://kiranc.co.uk/test/contact.aspx simply by filling in the form and trying to send it. I have done some googling, but haven't come up with anything useful yet...

    I am posting the code of interest (for reference)

    protected void sendEmail()
    {
    // send email
    btnSend.Visible = false;
    string mailBody = 'Name: ' + txtName.Text + '\n' +
    'Email: ' + txtEmail.Text + '\n' +
    'Tel: ' + txtTel.Text;
    MailMessage message = new MailMessage('mailTo', 'mailFrom',
    'ASP.NET Test Email', mailBody);
    SmtpClient emailClient = new SmtpClient('myemailserver');
    emailClient.Send(message); <---------------------- this line is where the error is occurring
    lblMsg.Text = 'Your email has been successfully sent!';
    }

    Any help would be much appreciated.

    Thanks.
     
  2. It's OK, this issue has now been resolved.

    I just happened to (coincidentally) come across a similar post where someone else was having a related problem;

    http://community.discountasp.net/default.aspx?f=24&m=18034

    Basically, the solution involved setting smtp server to localhost as Vikram stated, rather than the actual mail host, (which I thought it had to be!).
     

Share This Page