要减少公司中的邮件trafic,我正在为Outlook开发一个自定义功能区加载项。
这应该自动打开文件,以便他们的接收器知道他必须保存在哪里。因为这是一个特定的程序。
如何在特定邮件中的附件中获取文档的"路径"(双击邮件打开的邮件)?
i Aleady带有自定义按钮的丝带。但不能继续前进,因为我首先需要静止。
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void btnGerbv_Click(object sender, RibbonControlEventArgs e)
{
Forms.MessageBox.Show("Testing");
}
在这里看:
private void SaveMailAttachments(Outlook.MailItem mailItem)
{
Outlook.Attachments attachments = mailItem.Attachments;
if (attachments != null && attachments.Count > 0)
{
for (int i = 1; i <= attachments.Count; i++)
{
Outlook.Attachment attachment = attachments[i];
if (attachment.Type == Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue)
{
string filename = Path.Combine(@"d:", attachment.FileName);
attachment.SaveAsFile(filename);
}
}
}
}
和这里:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += new Microsoft.Office.Interop.Outlook
.ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}
private void ThisApplication_NewMail()
{
Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
.Session.GetDefaultFolder(Outlook
.OlDefaultFolders.olFolderInbox);
Outlook.Items inBoxItems = inBox.Items;
Outlook.MailItem newEmail = null;
inBoxItems = inBoxItems.Restrict("[Unread] = true");
try
{
foreach (object collectionItem in inBoxItems)
{
newEmail = collectionItem as Outlook.MailItem;
if (newEmail != null)
{
if (newEmail.Attachments.Count > 0)
{
for (int i = 1; i <= newEmail
.Attachments.Count; i++)
{
newEmail.Attachments[i].SaveAsFile
(@"C:TestFileSave" +
newEmail.Attachments[i].FileName);
}
}
}
}
}
catch (Exception ex)
{
string errorInfo = (string)ex.Message
.Substring(0, 11);
if (errorInfo == "Cannot save")
{
MessageBox.Show(@"Create Folder C:TestFileSave");
}
}
}