[英]Mail enabling an SPList programmatically
I am currently building a tool which creates SharePoint sites automatically. 我目前正在构建一个自动创建SharePoint网站的工具。 Each site must have a mailbox enabled and a specific Email address specified.
每个站点必须启用一个邮箱并指定一个特定的电子邮件地址。
I can create the site which by default has a SharePoint list named "mailbox". 我可以创建默认情况下具有名为“邮箱”的SharePoint列表的网站。
My questions is how to I allow the "mailbox" SPList to receive email. 我的问题是如何允许“邮箱” SPList接收电子邮件。 There is a property within an SPList called CanReceiveEmail but this is Read-only?
SPList中有一个名为CanReceiveEmail的属性,但这是只读的吗? So is there another way?
那么还有另一种方法吗?
I also need to be able to set the Email address of the SPList programtically, does anyone know the best way to do this? 我还需要能够以编程方式设置SPList的电子邮件地址,有人知道这样做的最佳方法吗?
It can be done manually but this is not an option. 可以手动完成,但这不是一个选择。
A simple list (as far as I know but I may be wrong) does not have the ability to receive emails. 一个简单的列表(据我所知,但我可能是错的)无法接收电子邮件。 You can create a custom list that does.
您可以创建一个自定义列表。
You can create a document library, which by default has this ability. 您可以创建一个文档库,默认情况下具有此功能。
How these properties are set, you can see when you examine the code (using Lutz Roeder's Reflector, http://www.red-gate.com/products/reflector/ ) of /_layouts/EmailSettings.aspx
which can be found in "Microsoft.SharePoint.ApplicationPages.dll" found on your server in path something like \\\\server\\c$\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\80\\_app_bin
. 如何设置这些属性,您可以查看
/_layouts/EmailSettings.aspx
的代码(使用Lutz Roeder的Reflector, http://www.red-gate.com/products/reflector/ ),该代码可以在“在服务器上的\\\\server\\c$\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\80\\_app_bin
类的路径中找到Microsoft.SharePoint.ApplicationPages.dll”。 So you will have to set multiple properties of the "rootfolder" of the document library. 因此,您将必须设置文档库的“ rootfolder”的多个属性。
The code is as follows : 代码如下:
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
EDIT: added comments to my code 编辑:添加注释到我的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.