Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to send an Smtp email using C#

Posted on 2010-11-30
2
Medium Priority
?
691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Written by Valentino Vranken. A while ago I wrote an article called Chart Optimization Tips (http://www.experts-exchange.com/articles/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Chart-Optimization-Tips.html).  This article explained how …
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

661 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