Search code examples
.netvbaoutlookoutlook-addin

VBA/.NET: Creating an Outlook rule for Reply-to


Using VBA or .NET for add-ins, is it possible to create an Outlook rule if the Reply-to contains a specific address?

My first problem is that the sender in the from field is different from the reply-to field. This is due to that the sender is sending an email through a mailing list.

There is no documented reply-to rule in the VBA enumeration object according to the MSDN documentation. Example of a rule that exists:

olConditionSenderAddress

The following rule does not exist:

olConditionReplyTo

Preferably, I would like to solve this using VBA, but if not possible I could resort to creating an add-in .NET application. However, there appears to be no ReplyTo property associated with the VBA Mailitem object.. There is, however, a MailMessage.ReplyTo property in the .NET DOM hierarchy, but the API is listed as obsolete.


EDIT: Apparently, ReplyRecipientsName is the correct VBA property to use.


Solution

  • Use Application_ItemSend event which fires when you press send button. You create this event in ThisOutlookSession module. Your event sub could look as below:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        With Item   'Item is your e-mail
    
            'to whom email
            Debug.Print .To
            'check if reply
            Debug.Print .ReplyRecipients.Count
    
            If .To = "ToEmail@Email" And .ReplyRecipients.Count > 0 Then
                'your logic
            End If
        End With
    End Sub