Outlook MailItem - определите, отправлен ли элемент или получен - PullRequest
0 голосов
/ 31 января 2020

В VBA, как определить, отправлен или получен почтовый элемент Outlook?

Ответы [ 3 ]

1 голос
/ 04 февраля 2020

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
1 голос
/ 31 января 2020

Это кажется достаточно общим:

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
0 голосов
/ 31 января 2020

Нет хорошего способа сделать это, единственный обходной путь - проверка свойства MailItem.ReceivedByName (или любого другого свойства ReceivedBy*) - он вернет пустую строку для сообщений из папки «Отправленные», отправленных текущий пользователь. Для полученных сообщений будет возвращено непустое значение.

...