简体   繁体   English

无法在自定义工作流sharepoint 2010中发送电子邮件

[英]Cannot send Email in custom workflow sharepoint 2010

I have some trouble when using SPUtility.SendEmail method in a custom workflow. 在自定义工作流程中使用SPUtility.SendEmail方法时遇到一些麻烦。

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. 在上面的代码中,方法SPUtility.SendEmail始终返回false。

I've even tried to use RunWithElevatedPrivileges, but still the method returns false. 我什至尝试使用RunWithElevatedPrivileges,但该方法仍返回false。

The smtp configuration is not the problem, because the standard email notification when a task is assigned in sharepoint is sent all right. smtp配置不是问题,因为可以正确发送在sharepoint中分配任务时的标准电子邮件通知。

The strange part is, I have tried this SendEmail method using a timer job, and the method is working perfectly fine. 奇怪的是,我已经使用计时器作业尝试了此SendEmail方法,并且该方法运行良好。

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). 我决定创建2个工作流程:第一个是使用启动参数发送电子邮件(使用sharepoint designer构建)。 the second one is workflow that initiate the first workflow. 第二个是启动第一个工作流程的工作流程。

it's now up and running. 现在启动并运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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