newjeep19
asked on
How to send an Smtp email using C#
I am trying to test sending an email from my web app that I developed in Visual Studio 2010. I am testing the application on my "local" server in which I have premission to send emails to our email server. When I click the submit button the button highlights but no email is sent. It is if no click event had occured.
Code:
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
mail.From = new MailAddress("myname@domain .net");
mail.To.Add("myname@domain name.net") ; // put To: address here
mail.Subject = "IT Account Request Form"; // put subject here
mail.Body = TextBox9.Text; // put body of email here
// put smtp server you will use here
SmtpClient smtp = new SmtpClient();
smtp.Host = "ip address for email server";
smtp.Port = 25;
smtp.Send(mail);
Label1.Text = "Your message was successfully sent.";
}
catch (Exception ex)
{
Label1.Text = "An error occurred sending your e-mail, the error is:\r\n" + ex.Message;
}
}
Code:
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
mail.From = new MailAddress("myname@domain
mail.To.Add("myname@domain
mail.Subject = "IT Account Request Form"; // put subject here
mail.Body = TextBox9.Text; // put body of email here
// put smtp server you will use here
SmtpClient smtp = new SmtpClient();
smtp.Host = "ip address for email server";
smtp.Port = 25;
smtp.Send(mail);
Label1.Text = "Your message was successfully sent.";
}
catch (Exception ex)
{
Label1.Text = "An error occurred sending your e-mail, the error is:\r\n" + ex.Message;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks