【发布时间】:2020-05-17 10:12:24
【问题描述】:
在 VBA 中,如何识别 Outlook MailItem 是已发送还是已接收?
【问题讨论】:
在 VBA 中,如何识别 Outlook MailItem 是已发送还是已接收?
【问题讨论】:
没有好的方法可以做到这一点,唯一的解决方法是检查MailItem.ReceivedByName 属性(或任何其他ReceivedBy* 属性)- 它会为来自已发送邮件文件夹的邮件返回一个空字符串当前用户。对于收到的消息,它会返回一个非空值。
【讨论】:
ReceivedByName 在发件人不在公司范围内时不起作用(因此只有电子邮件),但必须验证这一点...
item.ReceivedByName,即使我不是收件人之一,它们也会注明我的姓名。我收到的物品,也注明了我的名字(如预期的那样)。所以ReceivedByName 似乎根本无法按我的要求运行(Office 2013)
这似乎很笼统:
Public Enum MailItemStatus
Sent
Received
Draft
End Enum
Public Function getMailStatus(mItem as Mailitem) as MailItemStatus
if not mItem.sender is nothing then
If mItem.Sender.Address = Application.Session.CurrentUser.Address Then
if mItem.sent then
'Item is sent
getMailStatus = MailItemStatus.Sent
else
'Item is draft
getMailStatus = MailItemStatus.Draft
end if
else
'Item is received
getMailStatus = MailItemStatus.Received
end if
else
'Item is draft???
getMailStatus = MailItemStatus.Draft
end if
end function
【讨论】:
if mItem.sender is nothing then 你怎么能尝试在下一行得到mItem.Sender.Address?
Public Enum MailItemStatus
Sent
Received
Draft
End Enum
' Following the poster's Enum idea:
Public Function getMailStatus(mItem As MailItem) As MailItemStatus
If mItem.Sent Then
If mItem.Sender.Address = Session.CurrentUser.Address Then
getMailStatus = MailItemStatus.Sent
Else 'Item sent by someone who is not you
getMailStatus = MailItemStatus.Received
End If
Else 'Item has not been sent
getMailStatus = MailItemStatus.Draft
End If
End Function
【讨论】:
mItem.sent 而不是检查 mItem.sender 是有意义的。感谢您简化 :) 我确实还发现有 3 种状态。 mItem.Saved、mItem.Posted 和 mItem.Sent 我不确定 posted 是什么意思……