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

C# 无法在自定义工作流sharepoint 2010中发送电子邮件,c#,sharepoint,sharepoint-2010,sharepoint-workflow,C#,Sharepoint,Sharepoint 2010,Sharepoint Workflow,在自定义工作流中使用SPUtility.sendmail方法时遇到一些问题 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) { if (SPUtility.IsEmailServerSet(workflowProperties.Site.OpenWeb())) { StringDictionary headers =

在自定义工作流中使用SPUtility.sendmail方法时遇到一些问题

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");
            });
        }
    }
在上面的代码中,SPUtility.sendmail方法始终返回false

我甚至尝试使用RunWithElevatedPrivileges,但该方法仍然返回false

smtp配置不是问题,因为在sharepoint中分配任务时,标准电子邮件通知可以正常发送

奇怪的是,我已经尝试过使用计时器工作的SendEmail方法,该方法工作得非常好

请有人帮助我,如果有什么我需要添加到我的方法的上面


谢谢。

尝试获取提升权限范围内的web引用。

我找不到此问题的根源。 我决定创建2个工作流:第一个是使用initiation参数发送电子邮件(使用sharepoint designer构建)。第二个是启动第一个工作流的工作流

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");
            });
        }
    }
它现在已启动并运行。

您是否尝试使用该活动?