Outlook自定义插件代码未按预期工作(Downlaod电子邮件附件)
我正试图从outllok收到的邮件中解救附件。这是我的密码。我的问题是,当电子邮件到达时,它会正确下载当我的笔记本电脑打开时,但这封邮件安排在每天早上6点,我在9点打开我的笔记本电脑,邮件已经存在,并且没有按预期下载?我需要对代码做些什么吗Outlook自定义插件代码未按预期工作(Downlaod电子邮件附件),outlook,Outlook,我正试图从outllok收到的邮件中解救附件。这是我的密码。我的问题是,当电子邮件到达时,它会正确下载当我的笔记本电脑打开时,但这封邮件安排在每天早上6点,我在9点打开我的笔记本电脑,邮件已经存在,并且没有按预期下载?我需要对代码做些什么吗 const string destinationDirectory = @"\\prod_data\Service Now\"; Outlook.MAPIFolder inBox = this.Application.ActiveE
const string destinationDirectory = @"\\prod_data\Service Now\";
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++)
{
if (newEmail.Attachments[i].FileName.Contains( "LogicView Issue Report"))
{
newEmail.Attachments[i].SaveAsFile(destinationDirectory +
newEmail.Attachments[i].FileName);
}
}
}
}
}
}
我建议查一下房产的价值。它返回一个OlRemoteStatus常量,该常量在远程用户收到项目后确定项目的状态。例如:
Sub DownloadItems()
Dim mpfInbox As Outlook.Folder
Dim obj As Object
Dim i As Integer
Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
'Loop all items in the Inbox folder
For i = 1 To mpfInbox.Items.Count
Set obj = mpfInbox.Items.Item(i)
'Verify if the state of the item is olHeaderOnly
If obj.DownloadState = olHeaderOnly Then
MsgBox ("This item has not been fully downloaded.")
'Mark the item to be downloaded.
obj.MarkForDownload = olMarkedForDownload
End If
Next
End Sub
您可以使用SyncObject类的方法开始使用指定的发送\接收组同步用户的文件夹。不要使用Application.NewMail事件-仅当Exchange服务器接收电子邮件时Outlook正在运行时才会激发该事件
在收件箱文件夹Namespace.GetDefaultFolderolFolderInbox上使用Items.ItemAdd事件-当Outlook同步收件箱文件夹(假设您使用的是缓存模式)时,当电子邮件下载到缓存存储时,将触发该事件。如果Outlook处于联机状态,则不会触发任何事件。在这种情况下,您可以使用Items.Find/FindNext来处理所有未读邮件[unread]=“true”
你试过调试代码吗?你有错误吗?你什么时候运行代码?你能给我一个简单的项目代码吗?ItemAdd?那会很有帮助的
//declare on the global/class level to make sure
//it does not get garbage collected
private Outlook.Items inBoxItems;
...
//in your addin startup code
inBoxItems = inBox.Items
inBoxItems.ItemAdd += inboxItemsItemAdd;
...
private void inboxItemsItemAdd(object item)
{
...
}