Link to home
Start Free TrialLog in
Avatar of newjeep19
newjeep19Flag for United States of America

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@domainname.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;
            }
        }
ASKER CERTIFIED SOLUTION
Avatar of udaya kumar laligondla
udaya kumar laligondla
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newjeep19

ASKER

I was able to and the user name to the company's domain name by simply adding a + infront of the domain name i.e.  userName+"domain.net". That then sent the user name plus the company domain name in my email.
Thanks