Alex
Alex

Reputation: 97

Can I check if a recipient has an automatic reply before I send an email?

I have a macro set up that will automatically send out emails to dozens of managers. Sometimes they're away and I have to check the away message and manually forward it to the person covering for them.

I try to find a solution before I seek help so have mercy on me! I found a similar question but it wasn't a lot of help, I couldn't find a lot of info on extracting an auto response from a recipient in a draft.

So far this is what I've got:

Sub CheckAutoReply()

Dim OL As Outlook.Application
Dim EM As Outlook.MailItem
Dim R As Outlook.Recipient

Set OL = New Outlook.Application
Set EM = CreateItem(olMailItem)

With EM
    .display
    .To = "[email protected]" 'This is a recipient I know has an autoresponse. Fictitious of course.
End With

Set R = EM.Recipients(1) 'on hover it pops up with "EM.Recipients(1) = "[email protected]""

Debug.Print R.Name 'this returns "[email protected]"
Debug.Print R.AutoResponse 'this returns nothing

Set OL = Nothing
Set EM = Nothing

End Sub

Upvotes: 3

Views: 10014

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

The answer to the similar question you found (Remove recipients from Outlook email if automatic reply is activated) still stands. What were you having problem with?

The only additional possibility (and this is what Outlook uses when it displays an OOF banner for a recipient you are about to send to) is to use EWS and the GetMailTips operation (see https://msdn.microsoft.com/en-us/library/office/dd877060(v=exchg.150).aspx).

Upvotes: 1

Tony Dallimore
Tony Dallimore

Reputation: 12403

This is not a proper answer but an attempt to get you started.

Your code suggests your knowledge of Outlook VBA is limited. If this is true, I doubt that any of the approaches in “a similar question” will be appropriate. Are you familiar with Visual Studio, C++, Delphi or Redemption? Even if you managed to access PR_OOF_STATE, you would not have the alternative email address.

I would start by attempting to extract the email address from the out-of-office reply. Looking for “@” and extracting the text back to and forward to the next space might be enough.

Copy the code below to an Outlook VBA module. Select one of the out-of-office replies and run macro DemoExplorer. The objective of this macro is to show you what the text and Html bodies of the email look like. Try this macro on other replies. Are the bodies consistent? Can you see how to extract the alternative email address?

Public Sub DemoExplorer()

  Dim Exp As Outlook.Explorer
  Dim ItemCrnt As MailItem
  Dim NumSelected As Long

  Set Exp = Outlook.Application.ActiveExplorer

  NumSelected = Exp.Selection.Count

  If NumSelected = 0 Then
    Debug.Print "No emails selected"
  Else
    For Each ItemCrnt In Exp.Selection
      With ItemCrnt
        Debug.Print "From " & .SenderName & " Subject " & .Subject
        Debug.Print "Text " & Replace(Replace(Replace(.Body, vbLf, "{lf}"), vbCr, "{cr}"), vbTab, "{tb}")
        Debug.Print "Html " & Replace(Replace(Replace(.HTMLBody, vbLf, "{lf}"), vbCr, "{cr}"), vbTab, "{tb}")
      End With
    Next
  End If

End Sub

Upvotes: 1

Related Questions