Forward Email and Insert Sender's Email address in body

L

LDMueller

With the help of this awesome site, I've created the following code. The
only part which I can't figure out is how to insert the email address of the
sender in the
"Senders Email Address Here" area.

Sub Whitelist()
On Error Resume Next
Set ThisItem = Application.ActiveInspector.CurrentItem
Set fwdItem = ThisItem.Forward
fwdItem.To = "(e-mail address removed)"
fwdItem.subject = "Whitelist"
fwdItem.HTMLBody = "<p>Please whitelist the following:</p><p></p>" &
vbCrLf & _
"Senders Email Address Here" & _
vbCrLf & fwdItem.HTMLBody
fwdItem.Send
End Sub

Can anyone help me?

Thanks so much in advance!

LDMueller
 
K

Ken Slovak - [MVP - Outlook]

One post would have been enough.

You want the sender's email address from the ThisItem object?

Use ThisItem.SenderEmailAddress for that. Be aware though that if your
sender is an Exchange user in the same domain you are in (if you use
Exchange) that the result will be an Exchange DN and not an SMTP address.
 
L

LDMueller

Sorry about the duplicate post. When I went back to check the status and
didn't see the orginal one, I thought perhaps I didn't post it properly.

I tried your suggestion and it worked except my sender is an Exchange user.
Is there any way around this?

Also, the way I have it written, I have to have the email open for the macro
to work. Is there a way to have it work when the email is currently selected?

Thanks so much for your help. I really appreciate it!
 
K

Ken Slovak - [MVP - Outlook]

Assuming only 1 item is selected:
Application.ActiveExplorer.Selection.Item(1) instead of the
Inspector.CurrentItem.

What Outlook version are you using? If you are using Outlook 2007 or later
you can get the SMTP address, if you are using an earlier version of Outlook
you'd need to use a different, lower level API to get that property, which
isn't exposed in Outlook 2003 or earlier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top