0

My ultimate goal is to find a way to flag an email I am about to send with a reminder for both the person I am sending the email to and myself at today's date and time plus x amount of days. I've been able to do this when generating new mail items from Excel for years. The problem I'm having is doing this with a current item in Outlook 2016.

From Excel, I flag the email for followup by recipients and then just BCC myself. When the email is sent, it bounces back to me and I get the reminder because I am a recipient.

My first approach with Outlook VBA was to tag the email with a reminder for myself and also a category. The problem I had was, once the email was sent, it would remove the reminder for myself, but not the recipients. The category would still be attached though. So I decided to switch up and try the method I've been using with Excel.

Everything in this code works great. The email address is attaching, all of the prompts before are working, the reminder date is right. All working except for one thing. My email address in the BBC line is not resolving or not resolving quick enough, I'm not sure. The error message reads: "The operation failed. The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. Cannot resolve recipient."

Anyone know whats going on or if there is a way to force Outlook to resolve this email address before sending?

Private Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)

    Dim response As Integer
    Dim DaysToRemind As Byte

    response = MsgBox("Would you like to delay send this email?", vbYesNo)

    On Error GoTo Skip
    If response = vbYes Then olItem.DeferredDeliveryTime = Format(Date, "m/d/yyyy") & " 4:00:00 PM"

    On Error GoTo Skip
    If response = vbNo Then olItem.DeferredDeliveryTime = Now() - 1

    prompt$ = "Do you want to flag this message for followup?"

    If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
        DaysToRemind = InputBox("How many days to remind?", "Days Till Reminder", 3)

        With olItem
            .FlagStatus = olFlagMarked
            .FlagRequest = "Follow Up"
            .FlagDueBy = Now + DaysToRemind
            .Categories = "Waiting on Response"
            .BCC = "myemail@email.com"
            '.Save
            .Send
        End With

    End If

Skip:

End Sub

After some tooling with this, I had to end up setting up a rule to do everything I wanted to do, but it gets me to what I want essentially.

Private Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)

Dim response As Integer
Dim DaysToRemind As Byte

response = MsgBox("Would you like to delay send this email?", vbYesNo)

On Error GoTo Skip
If response = vbYes Then olItem.DeferredDeliveryTime = Format(Date, "m/d/yyyy") & " 4:00:00 PM"

On Error GoTo Skip
If response = vbNo Then olItem.DeferredDeliveryTime = Now() - 1

Des = MsgBox("Do you want to flag this message for followup?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?")

If Des = vbYes Then
    DaysToRemind = InputBox("How many days to remind?", "Days Till Reminder", 3)

    With olItem
        .FlagStatus = olFlagMarked
        .FlagRequest = "Follow Up"
        .FlagDueBy = Now + DaysToRemind
        If Right(.Subject, 4) <> " (T)" Then .Subject = .Subject & " (T)"
         Set myEmail = .recipients.Add("email@email.com")
         myEmail.Type = olBCC
         myEmail.Resolve
        .Save
    End With
End If

If Des = vbNo Then
     If Right(olItem.Subject, 4) = " (T)" Then olItem.Subject = Left(olItem.Subject, Len(olItem.Subject) - 4)
End If

Skip:

End Sub

Thanks all

  • Just a thought but you are missing .TO address - you are trying to send an email without an addressee, but only with .BCC - or maybe I'm not fully understanding what you are doing. – BobSki Sep 01 '17 at 15:16
  • This code runs after I've typed up an email and hit the send button, so I've already filled in the TO part, the subject and the body. It then asks me if I want to delay the delivery until 4pm (if the message is not super important) or if I want to add a reminder. If I add the reminder, I want it to BCC my email address. – Ryan Richards Sep 01 '17 at 15:26
  • Once you do your .BCC line - do a Sleep 2000 - then check if your email address is there before .SEND. That would be something I'd try – BobSki Sep 01 '17 at 15:27
  • found this in microsoft suppoert - This issue occurs when a Google Apps Sync for Microsoft Outlook account and a Microsoft Exchange Server account are configured in the same Outlook profile. – BobSki Sep 01 '17 at 15:29
  • Ahhhh. So my Gmail account tied to Outllok is causing it? – Ryan Richards Sep 01 '17 at 15:35
  • Could be it. Outlook is really stubborn with some things. It's a matter of testing. Try .BCC to someone else's email. See if that works. Don't liknk up Gmail to Outlook see if that works. – BobSki Sep 01 '17 at 15:37
  • Do you know if there is a way to just skip resolving the name and just send it or do you have to resolve every name before sending? – Ryan Richards Sep 01 '17 at 15:54
  • http://www.ozgrid.com/forum/showthread.php?t=160773 – BobSki Sep 01 '17 at 15:58

1 Answers1

0

You should not be calling MailItem.Send in the Application.ItemSend event handler that processes that very item. Just let Outlook proceed with the default behavior.
You should also not replace all BCC recipients by setting the BCC property: call MailItem.Recipients.Add and set the Recipient.Type property to olBCC

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks, after a little more searching I found out how to do what you described and get Outlook to resolve the names. I had to setup a rule to flag the message to do other things when it came back to me. – Ryan Richards Sep 01 '17 at 18:31