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



2 thoughts on “C#: Sending Email

  • 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!


  • 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 )

Google photo

You are commenting using your Google 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