我想开发Office Outlook插件,以便在电子邮件附件超过20 MB到OneDrive或SharePoint Online时上传电子邮件附件,并在发送时为邮件正文添加附件链接。
我需要一些指南才能开始,只要告诉我方向,我就会走它。
更新: 我已经开发了一部分,但是一旦代码到达 clientContext.ExecuteQuery(); outlook崩溃。
private void ApplicationOnItemSend(object item, ref bool cancel)
{
var mailItem = item as Outlook.MailItem;
//Upload to SharePoint
foreach (Outlook.Attachment attachment in mailItem.Attachments)
{
if (IsAttachmentExceedLimit(attachment))
{
byte[] attachmentData = null;
// this is a standard attached object
attachmentData = attachment.PropertyAccessor.GetProperty(PrAttachDataBin) as byte[];
MemoryStream theMemStream = new MemoryStream();
theMemStream.Write(attachmentData, 0, attachmentData.Length);
theMemStream.Position = 0;
try
{
//Upload attachment to SharePoint Online
bool overwrite = Settings.Default.Overwrite;
using (ClientContext clientContext = ClaimClientContext.GetAuthenticatedContext(Settings.Default.SharePointSiteUrl))
{
var web = clientContext.Web;
var list = web.Lists.GetByTitle(Settings.Default.SharePointFolder);
var newFileFromComputer = new FileCreationInformation
{
Content = attachmentData,
Url = attachment.FileName
};
var uploadedFile = list.RootFolder.Files.Add(newFileFromComputer);
clientContext.Load(uploadedFile);
clientContext.RequestTimeout = 360000000;
clientContext.ExecuteQuery();
}
//Add Link for attachment
mailItem.HTMLBody += Settings.Default.SharePointSiteUrl + Settings.Default.SharePointFolder +
attachment.FileName + Environment.NewLine;
//Delete attachement from mail message
mailItem.Attachments.Remove(attachment.Index);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
注意: 我对VSTO没有任何经验。