Sharepoint Send Email workaround via WCF Service

When you try to send an email with classical way in WCF service which is served in sharepoint you probably getting an error. As a workaround, you have to set HttpContext.Current = null. it will use the right context .

Here is the example:

try {    using (SPSite site = new SPSite(""))    {        SPWeb web = site.RootWeb;         {             //Save context to temp variable than set null             HttpContext tempContext = HttpContext.Current;             HttpContext.Current = null;             string MailTo = "";             string Subject = "Make it easy";             string Body = "A message from Bugra";             bool success = SPUtility.SendEmail(web, true, true, MailTo, Subject, Body);             HttpContext.Current = tempContext;         }     } } catch (Exception ex) {     // Exception Handling }
Happy coddings...



About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: