C#: Sending Email

To send email from your application or website do the following:

1. Add this config entry to your (App)(Web).config altering the host to the URL or IP address of your email server with the associated credentials.



            <smtp from="noreply@medimedia.com">

                <network host="localhost" password="" userName="" />




2. Use the following code to create and send a MailMessage

Version:0.9 StartHTML:0000000105 EndHTML:0000007499 StartFragment:0000000105 EndFragment:0000007499

        private void SendEmail()


            MailMessage message = new MailMessage();

            message.From = new MailAddress(_fromEmail);

            foreach (string email in _emailList)


                message.To.Add(new MailAddress(email));


            message.Subject =  _subject;

            message.IsBodyHtml = false;

            message.Priority = MailPriority.High;             

            message.Body = _body;



                SmtpClient client = new SmtpClient();



            catch (Exception ex)


               //TODO: Handle exception



Published by

Tim Clark

Experienced Business Owner, Chief Information Officer, Vice President, Chief Software Architect, Application Architect, Project Manager, Software Developer, Senior Web Developer, Graphic Designer & 3D Modeler, University Instructor, University Program Chair, Academic Director. Specialties: Ruby, Ruby on Rails, JavaScript, JQuery, AJAX, Node.js, React.js, Angular.js, MySQL, PostgreSQL, MongoDB, SQL Server, Responsive Design, HTML5, XHTML, CSS3, C#, ASP.net, Project Management, System Design/Architecture, Web Design, Web Development, Adobe CS6 (Photoshop, Illustrator)

2 thoughts on “C#: Sending Email

  1. Hey Tim, how's life!

    We were just thinking about you because John told me that he thinks you live in Daybreak. I'm moving there on October 5th!

    And I then stumbled upon your blog, I also have a blog on wordpress and I have not figured out how to easily add code to it. What plugin or theme allows you to display code the way it looks like on your blog?

    I hope life is treating you awesome!


  2. Hey Pedro,

    Nice to hear from you. How did you know this was my blog? I don't think my real name is anywhere on it, but I believe it is on my LinkedIn profile so maybe that how you knew. Anyway, you are correct I am living in Daybreak, its a great place, we really like it. Make sure you take boat out on the lake its a blast.

    The plugin I am using is for VS2005 and 2008, its called 'CopySourceAsHTML'. It allows you to modify the styles, its pretty configurable.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s