SharePoint – Send HTML Email with CC, BCC

Ref: http://www.dennispoint.com/Lists/Posts/Post.aspx?ID=28

This is something I needed for one of the projects I worked for in Omaha where they needed the ability to send HTML-formatted emails and be able to define the CC and BCC fields in the email.

So I created a method to do this :)

 

/// <summary>


/// Send an html email message


/// </summary>


/// <param name="web">SPWeb</param>


/// <param name="toEmail">email addresses, semi-colon seperated</param>


/// <param name="ccEmail">email addresses, semi-colon seperated</param>


/// <param name="bccEmail">email addresses, semi-colon seperated</param>


/// <param name="subject">email subject</param>


/// <param name="body">HTML email body</param>


public static void SendEmail(SPWeb web, string toEmail, string ccEmail, 


                             string bccEmail,


                             string subject, string body)


{


    if (!string.IsNullOrEmpty(toEmail))


    {


        StringDictionary headers = new StringDictionary


                                       {


                                           //{"from", "dalzoubi@the-e.net"},


                                           {"to", toEmail},


                                           {"cc", ccEmail},


                                           {"bcc", bccEmail},


                                           {"subject", subject},


                                           {"content-type", "text/html"}


                                       };


 


        SPUtility.SendEmail(web, headers, body);


    }


}



This can also be used with SharePoint workflows by calling this method from within a code activity




 

Comments

Popular posts from this blog

Referencing Javascript Files with SharePoint 2010 Custom Actions using SciptSrc

Configure Excel Services data access by using external data connection

Uninstall SQL Server Embedded