HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email

Sabastian Samuel

New Member
Outlook version
Outlook 2016 64 bit
Email Account
IMAP
I WOULD REALLY APPRECIATE IT IF SOMEONE COULD HELP ME OUT. IVE BEEN TRYING TO UNDERSTAND MACRO LANGUAGE FOR AGES AND I CANT SEEM TO GET ANYWHERE!
HERE IS WHAT I WANT TO DO. I hope this makes sense.

----

I want a macro to read every email that gets sent to my inbox.

IF the subject line begins with "Lost Property at"
THEN extract the whole body of the email as a string - string name "BODY"

SPLIT the the string at the point where "\split" is in the text

I should have these strings only now

BODY_1
BODY_2


i dont think there is a chance of \split being in the body more than once. but if it is, i would want to isolate BODY_1 and concatenate the rest together

I now want the macro to write an email:

to: BODY_1
subject
: the subject of the original email
body: BODY_2

SEND
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can use it either in a run a script rule or watch the folder and process it using an itemadd macro.
Outlook's Rules and Alerts: Run a Script
How to use an ItemAdd Macro


this snippet will do what you need (i think the array code is correct, but it might need tweaked)-

if lcase(item.subject) = "lost property" then
Dim BodyArray() As variant

BodyArray() = (item.body, "\split", 2)

--create new message --
Create a new Outlook message using VBA

then use this:
newMsg.to = bodyarray(1)
newMsg.body = bodyarray(2)
newMsg.send

end if
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you need to set the item object to a message - this will use the selected message (great for testing - change it to use incoming messages later)

sub lostpropertyforward()
Set Item = application.ActiveExplorer.Selection.Item(1)
' rest of your code
end sub
 
Top