Solved

How to send an Smtp email using C#

Posted on 2010-11-30
2
678 Views
Last Modified: 2012-05-10
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;
            }
        }
0
Comment
Question by:newjeep19
2 Comments
 
LVL 12

Accepted Solution

by:
udayakumarlm earned 500 total points
Comment Utility
is there a change in the lable1 text. put a break point on line with try statement and check where the process is exiting and if there is a error message post the same. check your mail server port number, check if user name password are required for your SMTP server.
0
 

Author Closing Comment

by:newjeep19
Comment Utility
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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now