0

I have one application which will create task form for each level based on the prior level approval. While creating each tasks I have to send the email to the users who all are involved in the task. For this I am using SPUtility.SendEmail() method. But unfortunately, it didn't work so far. The debugger successfully passed through the SendEmail method without any exception. but the value will always false. The SMTP server is working for the application other than the SP Applications. My code is shown below.

  SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite spSite = new SPSite(SiteURL))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        headers = new StringDictionary();
                        headers.Add("to", To);
                        headers.Add("from", From);
                        headers.Add("cc", CC);
                        headers.Add("bcc", BCC);
                        if (Priority.Equals("High"))
                        {
                            headers.Add("X-Priority", "1 (Highest)");
                            headers.Add("X-MSMail-Priority", "High");
                            headers.Add("Importance", "High");
                        }
                        headers.Add("subject", Subject);
                        headers.Add("content-type", "text/html");
                        Status= SPUtility.SendEmail(spWeb, headers, Body);
                    }
                }
            });

Please help me to resolve this issue. All Suggestions would be appreciated. Thanks in advance.

4
  • Does it work without your "special" headers, with just subject left? May 14, 2014 at 11:11
  • @RobertLindgren: No. It didn't work..
    – MAC
    May 14, 2014 at 11:49
  • And SharePoint outgoing email is configured and working? May 14, 2014 at 11:51
  • @RobertLindgren: Yes, everything except this SPUtility Send Email are working.
    – MAC
    May 15, 2014 at 5:25

2 Answers 2

0

You are creating a StringDictionary() but not using the overload of SPUtility.SendEmail which uses StringDictionary as one of the parameters SPUtility.SendEmail Method (SPWeb, StringDictionary, String)

1
  • I was used the StringDictionary. For the testing purpose I have changed the code today itself. Please check my code now.
    – MAC
    May 14, 2014 at 10:55
0

We struggled with same issue. What we realized that SPUtility.SendEmail did not work when it was written inside SPSecurity.RunWithElevatedPrivileges. I couldn't find any specific reason for this. As a workaround we used MailMessage to send email.

MailMessage message = new MailMessage(<mailFrom>, <recipientMail>);
message.Subject = "<Subject>";
message.Body = "<BODY>";
SmtpClient smtp = new SmtpClient(<mailServer>, <mailPort>);
smtp.Send(message);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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