获取“发件人"和“电子邮件正文"特性 [英] Obtain "sender" and "emailbody" properties
问题描述
背景
我扫描Outlook中的收件箱,然后根据电子邮件标题将结果报告给Excel电子表格.我将使用与Microsoft Office关键字相同的示例,并说"Office".
Background
I scan the inbox in Outlook and report the results to a Excel spreadsheet based on the Title of the email. I will use the same example as in Microsoft office keyword and will say "Office".
IE:Office:笔记本电脑问题.
我需要获取发送邮件的用户名或电子邮件地址,以及电子邮件本身中的一些关键字.
我找到了仅通过使用表和行来迭代具有此关键字的项目的方法.
IE: Office: Problem with Laptop.
I need to get the user name or email address that sent the mail and probably some keywords in the body of the email itself.
I found the way to iterate through the items that have this keyword only by using tables and rows.
问题
我无法找到将表中的row.item转换为电子邮件的方法,也无法获得发件人"或电子邮件主体"属性.
Problem
I have not been able to find a way to cast the row.item from the table to an email nor to obtain "sender" or "emailbody" properties.
代码
您需要添加Outlook参考
Code
You need to add Outlook reference
Option Base 1
Sub Outlook_ScanForEmails()
Const TxtTag As String = "http://schemas.microsoft.com/mapi/proptag/"
Const TxtWordSubject As String = "Office:"
Dim OutTable As Outlook.Table
Dim OutRow As Outlook.Row
Dim OutEmail As Outlook.MailItem
Dim OutApp As Outlook.Application: Set OutApp = New Outlook.Application
Dim CounterEmails As Long
Dim TotalEmails As Long
Dim TxtFilter As String: TxtFilter = "@SQL=" & Chr(34) & TxtTag & "0x0037001E" & Chr(34) & " ci_phrasematch '" & TxtWordSubject & "'"
Dim TxtCourse As String
Dim DteReport As Date
Set OutTable = OutApp.Session.GetDefaultFolder(olFolderInbox).GetTable(TxtFilter)
TotalEmails = OutTable.GetRowCount
For CounterEmails = 1 To TotalEmails
Set OutRow = OutTable.GetNextRow
DteReport = OutRow("LastModificationTime")
TxtCourse = OutRow("Subject")
TxtCourse = Right(TxtCourse, Len(TxtCourse) - Len(TxtWordSubject))
Next CounterEmails
End Sub
其他想法
我宁愿不遍历每封电子邮件,因为该表将整个过程缩小为仅遍历我需要的行项目.
Further thoughts
I would prefer to not iterate through each email since the table narrows the process to iterating only the row items I need.
推荐答案
根据我的评论,您可以从表的entryID列中获取邮件项目.这是如何完成此操作的示例.
Per my comment you can get a mail item from the entryID column of the table. Here is an example of how to accomplish this.
Option Base 1
Sub Outlook_ScanForEmails()
Const TxtTag As String = "http://schemas.microsoft.com/mapi/proptag/"
Const TxtWordSubject As String = "Office:"
Dim OutTable As Outlook.Table
Dim OutRow As Outlook.Row
Dim OutEmail As Outlook.MailItem
Dim OutApp As Outlook.Application: Set OutApp = New Outlook.Application
Dim CounterEmails As Long
Dim TotalEmails As Long
Dim TxtFilter As String: TxtFilter = "@SQL=" & Chr(34) & TxtTag & "0x0037001E" & Chr(34) & " ci_phrasematch '" & TxtWordSubject & "'"
Dim TxtCourse As String
Dim DteReport As Date
Set OutTable = OutApp.Session.GetDefaultFolder(olFolderInbox).GetTable()
TotalEmails = OutTable.GetRowCount
For CounterEmails = 1 To TotalEmails
Set OutRow = OutTable.GetNextRow
DteReport = OutRow("LastModificationTime")
TxtCourse = OutRow("Subject")
'Define a string for the EntryId
Dim entryID As String
'get EntrId
entryID = OutRow("EntryID")
'define a MailItem
Dim mi As MailItem
'Get the MailItem from the ID
Set mi = OutApp.Session.GetItemFromID(entryID)
'do something with the mail item
TxtCourse = Right(TxtCourse, Len(TxtCourse) - Len(TxtWordSubject))
Next CounterEmails
End Sub
这篇关于获取“发件人"和“电子邮件正文"特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!