Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to send an Smtp email using C#

Posted on 2010-11-30
2
Medium Priority
?
694 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:
udaya kumar laligondla earned 1000 total points
ID: 34246369
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
ID: 34247936
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi All, I am here to write a simple article to move SSRS (SQL Server Reporting Services) reports from one server to another. When I have faced the same issue to move reports those were developed by developer on development server and now need to …
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

926 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