Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29919

How to get a sender's email address?

$
0
0

I want Outlook to perform an action on email from a certain email address.

In the ThisOutlookSession I have:

Private Sub Application_NewMail() 'This triggers when a new email is recieved
    Call TestSub
End Sub

In a module I have:

Public Sub TestSub()
    Dim Msg                 As Outlook.MailItem
    Dim FromEmailAddress    As String

    FromEmailAddress = Msg.SenderEmailAddress

    If FromEmailAddress = "Test@example.com" Then
        MsgBox ("Hello")
    End If

End Sub

I get

Run-time error '91':
Object variable or With block variable not set

on FromEmailAddress = Msg.SenderEmailAddress.

I have tried many variations on my code and exhausted the powers of Google.


Viewing all articles
Browse latest Browse all 29919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>