开发者

Cannot send Email in custom workflow sharepoint 2010

开发者 https://www.devze.com 2023-04-11 07:37 出处:网络
I have some trouble when using SPUtility.SendEmail method in a custom workflow. private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)

I have some trouble when using SPUtility.SendEmail method in a custom workflow.

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
    {
        if (SPUtility.IsEmailServerSet(workflowProperties.Site.OpenWeb()))
        {
            StringDictionary headers = new StringDictionary();
            headers.Add("to", "myemailaddress@mailinator.com");
            headers.Add("from", "somebody@example.com");
            headers.Add("content-type", "text/html");

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                bool test = SPUtility.SendEmail(web, headers, "some message body");
            });
        }
    }

in the code's above, the method SPUtility.SendEmail always returning false.

I've even tried to use RunWithElevatedPrivileges, but still the method returns false.

The smtp configuration is not the problem, because the standard email notification when a task is assigned in sharepoint is sent a开发者_如何学Goll right.

The strange part is, I have tried this SendEmail method using a timer job, and the method is working perfectly fine.

please somebody help me if there is something i need to add to my method's above.

thanks.


Try to get the web reference in the elevated privileges scope.


I couldn't find the root of this problem. I decided to do create 2 workflow: the first is to send the email using initiation parameter (build using sharepoint designer). the second one is workflow that initiate the first workflow.

it's now up and running.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号