如何在电子邮件移动时MailItem.EntryID更改时唯一标识Outlook电子邮件 [英] How to uniquely identify an Outlook email as MailItem.EntryID changes when email is moved

查看:278
本文介绍了如何在电子邮件移动时MailItem.EntryID更改时唯一标识Outlook电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司使用单一的电子邮件地址给客户发送请求和订单。我们创建了一个Access数据库,将电子邮件导入表中。该表创建它是导入的每个电子邮件的唯一标识符,但不应该导入电子邮件两次。系统正在工作,因为我们只关心邮件进入收件箱,不需要任何东西。

My company uses a single email address for customers to send requests and orders to. we created an Access database that import emails into a table. The table creates it's own unique identifier for each email imported but is not supposed to import an email twice. The system was working as we were only concerned with emails coming into the inbox and didn't need anything more than that.

然而,我们现在需要知道流 ,这个帐号的电子邮件池的流量和工作量。进入收件箱的电子邮件被分类,然后移动到一个名为my_tasks的文件夹和一个子文件夹,名称为管理员要处理的四个CSR中的1个文件夹。然后处理此电子邮件,CSR将其移动到名为已完成的另一个文件夹下的子文件夹。

However we now need to know the "flow", "traffic" and "workload" of the email pool that this account is. The email that comes into the inbox is categorized and then moved to a folder called "my_tasks" and a subfolder the folder named as 1 of the four CSRs to be worked on by a manager. This email is then dealt with and the CSR moves it to a subfolder under another folder called "Completed".

所以电子邮件进入收件箱,移动到my_tasks\joeblow被处理并被移动到Completed\Canada。

So email comes into Inbox, gets moved to my_tasks\joeblow is dealt with and gets moved to Completed\Canada.

目前,我有代码遍历文件夹并查找每个电子邮件,抓住我们要存储的字段,然后将它们插入表中。所有这些都是通过VBA代码访问的。

Currently I have code that iterates through the folders and finds each email, grabs the fields we want to store and then inserts them into the table. All of this is done in Access through VBA code.

Private Sub ImportEmailItem(objMailItem As Outlook.MailItem)
On Error GoTo ImportEmailItem_Error

    ' Set up DAO objects
    Dim rstMB As DAO.Recordset
    Dim dskippedFolderMailCount As Double
    Dim strSQLrMB As String

    strSQLrMB = "SELECT * FROM tblMailBox WHERE OLID='" & objMailItem.EntryID & "'"

    Set rstMB = CurrentDb.OpenRecordset(strSQLrMB)

        With rstMB
            If Not .BOF And Not .EOF Then

                .MoveLast
                .MoveFirst
                While (Not .EOF)
                    If .Updatable Then
                        .Edit
                            rstMB!Subject = objMailItem.Subject
                            rstMB!Body = objMailItem.Body

                            Call subCategory(objMailItem)

                            rstMB!CSR = IIf(Len(objMailItem.Categories) = 0, "Unassigned", objMailItem.Categories)
                            rstMB!Importance = objMailItem.Importance
                            rstMB!Region = objMailItem.Parent
                            rstMB!DateModified = objMailItem.LastModificationTime
                            rstMB!FlagCompleted = objMailItem.FlagRequest
                            rstMB!folder = objMailItem.Parent
                            rstMB!Path = objMailItem
                        .Update
                    End If
                .MoveNext
                Wend
            Else
                rstMB.AddNew
                    rstMB!olid = objMailItem.EntryID
                    rstMB!ConversationIndex = objMailItem.ConversationIndex
                    rstMB!ConversationID = objMailItem.ConversationID
                    rstMB!Conversation = objMailItem.ConversationTopic
                    rstMB!To = Left(objMailItem.To, 250)
                    rstMB!CC = Left(objMailItem.CC, 250)
                    rstMB!Subject = objMailItem.Subject
                    rstMB!Body = objMailItem.Body

                    Call subCategory(objMailItem)

                    rstMB!CSR = IIf(Len(objMailItem.Categories) = 0, "Unassigned", objMailItem.Categories)
                    rstMB!Importance = objMailItem.Importance
                    rstMB!From = objMailItem.SenderEmailAddress
                    rstMB!Region = objMailItem.Parent
                    rstMB!DateReceived = objMailItem.ReceivedTime
                    rstMB!DateSent = objMailItem.SentOn
                    rstMB!DateCreated = objMailItem.CreationTime
                    rstMB!DateModified = objMailItem.LastModificationTime
                    rstMB!FlagCompleted = objMailItem.FlagRequest
                    rstMB!folder = objMailItem.Parent
                rstMB.Update
            End If
            .Close
        End With

ImportEmailItem_Exit:
    Set rstMB = Nothing
    Exit Sub

ImportEmailItem_Error:
    Debug.Print Err.Number & " " & Err.Description

    Select Case Err.Number
        Case 91
            Resume Next
        Case 3022
            Resume Next
        Case -2147221233
            MsgBox "Customer Care Account Name is incorrect, please enter the Mail box name as seen in your outlook client.", vbOKOnly, "Mail Folder Name Error"
            Me.txtMailAccountName.SetFocus
            Exit Sub
        Case Else
            MsgBox "Error #: " & Err.Number & "  " & Err.Description '& Chr(13) + Chr(10) & IIf(mail.Subject Is Null, "", mail.Subject) & " " & IIf(mail.ReceivedTime Is Null, "", mail.ReceivedTime)
'            DoCmd.RunSQL "INSERT INTO tblImportReport(ImportDate,ImportFolder,ImportResult,ImportEmailCount) VALUES (#" & Now() & "#,'" & mailFolder & "', 'Error " & Err.Number & "', " & dMailCount & ")"
            Resume Next 'cmdImportEmail_Exit
    End Select

End Sub

有没有办法唯一标识一个字段的电子邮件,无论如何是否已被移动?

Is there a way to uniquely identify an email with a single field no matter whether it has been moved or not?

我有一个想法,我可以做什么,以确保我有正确的电子邮件,并获取我的数据库中的原始条目。如果没有其他方式,我可以将字段连接在一起形成一个唯一的字段,然后获取数据库表的主键字段值。

I have an idea of what I could do to make sure I have the right email and get the original entry in my database. If there was no other way I could concatenate fields together to form a unique field and then get the database table's primary key field value.

推荐答案

p>您可以使用PR_SEARCH_KEY属性(DASL名称 http://schemas.microsoft.com/mapi/proptag/0x300B0102 ) - 消息移动时不会更改。它可以通过MailItem.PropertyAccessor.GetProperty访问,但不幸的是您不能在Items.Find / Restrict中使用PT_BINARY属性。

You can use the PR_SEARCH_KEY property (DASL name http://schemas.microsoft.com/mapi/proptag/0x300B0102) - it does not change when a message is moved. It can be accessed through MailItem.PropertyAccessor.GetProperty, but unfortunately you cannot use PT_BINARY properties in Items.Find/Restrict.

您还可以使用MailItem设置自己的命名属性.UserProperties。

You can also set your own named property using MailItem.UserProperties.

更新:

对于PR_SEARCH_KEY,请参阅 https://msdn.microsoft.com/en-us/library/office/cc815908.aspx

For PR_SEARCH_KEY, see https://msdn.microsoft.com/en-us/library/office/cc815908.aspx.

MaillItem.UserProperties可以在任何地方使用 - Outlook对象模型是Outlook对象模型,无论是从Outlook内部还是外部使用Excel。请记住,设置用户属性并拖动项目将更改其上次修改的日期。

MaillItem.UserProperties can be used from anywhere - Outlook Object Model is Outlook Object Model whether it is used from inside Outlook or externally from Excel. Keep in mind that setting a user property and daving the item will change its last modified date.

如果要坚持PR_SEARCH_KEY,可以对其进行排序,您可能需要查看兑换 - 其 RDOFolder.Items .Find / Restrict方法允许其查询中的PT_BINARY属性,例如http://schemas.microsoft.com/mapi/proptag/0x300B0102='89F75D48972B384EB2C50266D1541099'

If you want to stick to PR_SEARCH_KEY, to be be able to sort on it, you might want to look at Redemption - its RDOFolder.Items.Find / Restrict methods allow PT_BINARY properties in its queries, e.g. "http://schemas.microsoft.com/mapi/proptag/0x300B0102" = '89F75D48972B384EB2C50266D1541099'

这篇关于如何在电子邮件移动时MailItem.EntryID更改时唯一标识Outlook电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆