以编程方式启用SPList的邮件

时间:2010-01-07 16:28:10

标签: c# asp.net sharepoint moss

我目前正在构建一个自动创建SharePoint网站的工具。每个站点都必须启用邮箱并指定特定的电子邮件地址。

我可以创建默认情况下具有名为“mailbox”的SharePoint列表的网站。

我的问题是如何让“邮箱”SPList接收电子邮件。 SPList中有一个名为CanReceiveEmail的属性,但这是只读的?那还有另一种方式吗?

我还需要能够以编程方式设置SPList的电子邮件地址,有没有人知道最好的方法呢?

可以手动完成,但这不是一个选项。

1 个答案:

答案 0 :(得分:0)

一个简单的列表(据我所知,但我可能错了)没有能力接收电子邮件。您可以创建一个自定义列表 您可以创建一个文档库,默认情况下具有此功能。

如何设置这些属性,您可以看到检查/_layouts/EmailSettings.aspx的{​​{1}}的代码(可以在“Microsoft.SharePoint.ApplicationPages.dll”中找到)找到的代码(使用Lutz Roeder的Reflector,http://www.red-gate.com/products/reflector/)在您的服务器上的路径类似 \\server\c$\Inetpub\wwwroot\wss\VirtualDirectories\80\_app_bin。 因此,您必须设置文档库“rootfolder”的多个属性。

代码如下:

Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal args As EventArgs)
    If Me.EnabledTrue.Checked Then
        If ((Me.TxtAlias.Text Is Nothing) OrElse (Me.TxtAlias.Text.Length = 0)) Then
            Throw New SPException(SPResource.GetString("MissingEmailAlias", New Object(0  - 1) {}))
        End If

        'This will be the receiving e-mail address
        Me.m_List.EmailAlias = Me.TxtAlias.Text

        'do we need to check users permissions on items
        Me.m_RootFolder.Properties.Item("vti_emailusesecurity") = IIf(Me.UseSecurityTrue.Checked, 1, 0)

        If Me.ShowSaveAttachments Then
            'options how to save attachments, root folder, grouped, whatever
            Me.m_RootFolder.Properties.Item("vti_emailsaveattachments") = IIf(Me.SaveAttachmentsTrue.Checked, 1, 0)
        End If
        If Me.ShowSaveOriginalAndMeetings Then
            Me.m_RootFolder.Properties.Item("vti_emailsavemeetings") = IIf(Me.MeetingsTrue.Checked, 1, 0)
            Me.m_RootFolder.Properties.Item("vti_emailsaveoriginal") = IIf(Me.SaveOriginalTrue.Checked, 1, 0)
        End If

        If Me.ShowAttachmentFolders Then
            Me.m_RootFolder.Properties.Item("vti_emailoverwrite") = IIf(Me.OverwriteTrue.Checked, 1, 0)
            If Me.AttachmentFoldersSender.Checked Then
                Me.m_RootFolder.Properties.Item("vti_emailattachmentfolders") = "sender"
            ElseIf Me.AttachmentFoldersSubject.Checked Then
                Me.m_RootFolder.Properties.Item("vti_emailattachmentfolders") = "subject"
            Else
                Me.m_RootFolder.Properties.Item("vti_emailattachmentfolders") = "root"
            End If
        End If
        If Me.ShowAutoApprove Then
            'I think this is something when content approval is enabled.
            Me.m_RootFolder.Properties.Item("vti_emailautoapprove") = IIf(Me.AutoApproveTrue.Checked, 1, 0)
        End If
    ElseIf Me.EnabledFalse.Checked Then
        Me.m_List.EmailAlias = Nothing
    End If
    Me.m_RootFolder.Update
    Me.m_List.ResetContentTypes
    Me.m_List.Update
    SPUtility.Redirect((IIf((Me.m_List.BaseType = SPBaseType.Survey), "survedit", "listedit") & ".aspx?List=" & Me.m_List.ID.ToString), SPRedirectFlags.RelativeToLocalizedLayoutsPage, Me.Context)
End Sub

编辑:在我的代码中添加了评论