Add text to auto-forwarded e-mail

Zelatvian

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hello,

I've seen variations of this question floating around all over, but I have not managed to figure out how to adapt any of them to this specific need. Probably because the first time I even opened VB was yesterday haha.

So the issue I'm having:
At the moment I have a rule in Outlook to auto-forward e-mails from a specific sender that contain specific words in the e-mail body to one or multiple recipients. What I would like to do, is to add some text in the forwarded e-mail body, i.e "Please find the approval below".. As I understand then this should be doable using VB in Outlook, but I simply cannot wrap my three brain cells around it. Any help/ideas would be much appreciated!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange

Zelatvian

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hi, Diane!

Thanks for the hint - I tried to use it, and upon execution, it tried to forward all of my existing emails which means I'm doing something wrong hahaha.

I'd need this macro to pick up only e-mails that meet specific criteria combination: sender, keyword, subject & then trigger the forward with a message & attachment added to the forwarded e-mail body. It seems that this would require to have a combination of codes?
 

Zelatvian

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hi, in case anyone ever should possibly need such a solution, here's the code that eventually worked for me:

Public Sub CreateCustomMail(item As Outlook.MailItem)
' Define new email object and variables
Dim NewEmail As Outlook.MailItem
Dim eRecipientsLV As String
Dim eRecipientsLT As String
Dim eRecipientsEE As String
Dim eBody As String

' Set values
Set NewEmail = item.Forward
' ## Change the eRecipients value to the name of your Contact Group
eRecipientsLV = "RecipientsLV"
'eRecipientsLT = "RecipientsLT"
'eRecipientsEE = "RecipientsEE"
' ## Change the addToBody value to change the text in your forwarded mail.
' ## NOTE: This is HTML formatted text
addToBody = "Hello, <p><p>please see for approval,<p><p><br>Zelatvian"

' incoming email attributes converted to string for string comparisson
Dim mailSubject As String
mailSubject = item.Subject

' Format and forward actual email
With NewEmail
If InStr(mailSubject, "LV") > 0 Then
.Recipients.Add (eRecipientsLV)
End If
If InStr(mailSubject, "LT") > 0 Then
.Recipients.Add (eRecipientsLT)
End If
If InStr(mailSubject, "EE") > 0 Then
.Recipients.Add (eRecipientsEE)
End If
.Subject = "RE: " & item.Subject
.BodyFormat = olFormatHTML
.HTMLBody = addToBody & .HTMLBody
End With

NewEmail.Send
Set item = Nothing
Set NewEmail = Nothing
End Sub
 
Top