简体   繁体   中英

Cannot send Email in custom workflow sharepoint 2010

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 all 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.

尝试获取提升权限范围内的Web参考。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM