unable to send a mail through system.net api and sputility.sendmeail() .

I tried the below code for sending mail through the above. but it failed to send mail. But if I tried with PowerShell approach , I am able to send mails without any issues.

SPutility code :


                using (SPSite msite = new SPSite("http://sharepointuat:400/sites/dms"))
                    using (SPWeb mweb = msite.OpenWeb())
                        string from = "[email protected]";

                        string to = "[email protected];[email protected]";
                        string cc = "[email protected]";
                        string bcc = "";
                        string subject = "hello sendmail from SP 2010  THRU SPUTILITY";
                        string body = "hello sendmail from SP 2010  THRU SPUTILITY";

                        string emailSummary;
                        var messageHeaders = new StringDictionary();

                        messageHeaders.Add("to", to);
                        messageHeaders.Add("from", from);
                        messageHeaders.Add("subject", subject);
                        messageHeaders.Add("cc", cc);
                        messageHeaders.Add("bcc", bcc);
                        string mimeType = "text/html";
                        messageHeaders.Add("content-type", mimeType);

                        bool sendMail = SPUtility.SendEmail(mweb, messageHeaders, body)


        catch (Exception exp11)
            Console.WriteLine(exp11.Message + "__"  + exp11.StackTrace);
            throw exp11;

Powershell code which is working:

 #add-pssnapin "microsoft.sharepoint.powershell"
   $email = "[email protected];[email protected]"
   $subject = "mail.domain test subject1111"
    $body = "Test body2222 sending mail to S n p"
    $site = New-Object Microsoft.SharePoint.SPSite                
        $web = $site.OpenWeb()

The above PowerShell code is working fine.

I am in need of sending mail through sputility, C# & SharePoint SSOM.

Can anyone help , whether I am missing any parameter missing from my C# code?

  • The documentation for SPUtility.SendEmail method says "This method supports sending email messages only to valid SharePoint user email addresses.", msdn.microsoft.com/en-us/library/ms460489.aspx, are the addresses in TO header valid SharePoint user email addresses?
    – AmitWiki
    Sep 29, 2016 at 17:11
  • Yes.of course. The strange thing is that, it works in powershell. I have checked with correct valid user email ids only. Any other settings I need to do?
    – samolpp2
    Sep 29, 2016 at 17:14
  • Is this a console/windows app code or a web app code running on IIS?
    – AmitWiki
    Sep 29, 2016 at 17:17
  • For testing purposes I created a simple console application. But my actual environment is visual web part targeting in SP 2010 env
    – samolpp2
    Sep 29, 2016 at 17:21
  • even i tried with the system.net smtp.sendmail() as well. that also failed in sending the mail to target users! So is there any issue with smtp server? i for the sputility object,i have correctly mentioned/configured the outgoing emailsettings in my central admin. thats the reason thru powershell, i am able to send mails,but why sputility is not taking/reading the outgoing mail settings. v.strange issue.
    – samolpp2
    Sep 29, 2016 at 18:21

1 Answer 1


By default, SPUtility.SendEmail() method picks the From address from Outgoing E-Mail Settings in Central administration. Use SPUtility.IsEmailServerSet method to check if server is configured with SMTP mail settings.

You should use "," instead of ";" in the to field in the header.

Try below code:

using (SPSite oSPSite = new SPSite("https://sharepoint.com"))  //Site collection URL
                using (SPWeb oSPWeb = oSPSite.OpenWeb("News"))  //Subsite URL
                    StringDictionary headers = new StringDictionary();

                    headers.Add("from", "[email protected]");
                    headers.Add("to", "[email protected],[email protected]");
                    headers.Add("cc","[email protected]");
                    headers.Add("subject", "Welcome to the SharePoint");
                    headers.Add("fAppendHtmlTag","True"); //To enable HTML format

                    System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
                    strMessage.Append("Message from CEO:");

                    strMessage.Append("<span style='color:red;'> Make sure you have completed the survey! </span>");
                    SPUtility.SendEmail(oSPWeb, headers, strMessage.ToString());


Read more:

  • This worked well. Once caveat here. I found that in my implementation (certainly there are differences between the farms) -- when I included from in the headers dictionary, the SendEmail method returns true but the message is not delivered. However, by removing / commenting out that one line. It works for me. Hope that helps. Mar 27, 2018 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.