plz help sending Mail

Dec 2 2008 1:40 AM
Hi all,
        I am very much new to this.Here i have a code to just send a mail without any attachments.but i get the error wen i do that. Here is my code,


Code behind,

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

public partial class Mail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage mail = new MailMessage();
            mail.To = TextBox1.Text;
            mail.From = TextBox2.Text;
            mail.Subject = TextBox3.Text;
            mail.Body = TextBox4.Text;
            SmtpMail.SmtpServer = "192.168.0.40";
            SmtpMail.Send(mail);
            Label1.Text = "message sent succesfully";
        }
        catch (Exception ex)
        {
            Label1.Text = "message sending failed";
          
            Label2.Text = ex.Message.ToString();
            Label3.Text = ex.Source.ToString();
            Label4.Text = ex.TargetSite.ToString();


            Label5.Text = ex.StackTrace.ToString();
        }
    }
}



the error i get is,

Message: The transport failed to connect to the server.
Source: System.Web
Target: System.Object CallMethod(System.Object, System.String, System.Object[])
Stack: at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at Mail.Button1_Click(Object sender, EventArgs e) in d:\detail\Mail.aspx.cs:line 29

I know its a minor issue,but plz m new.


Answers (2)