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
 

Lewis-H

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Try my code. It worked fine for me using <Alt-F8> to launch the macro. Of course, I placed the macro in the ThisOutlookSession module. I tested this on several messages that had the text and one or more inline image(s), as well as some that had an attachment too. If the original has LOTS of linked inline images, be patient, as it can take a while to retrieve all of the original linked images from their server. However, embedded images should load more quickly.

Once you're comfortable with the macro, you can get rid of the . Display line and/or un-comment the .Save and .Send lines if you desire. If you assign it to your button and/or custom keyboard shortcut, the forward will be very automated.

[vba]
Sub ForwardEmail()

Dim oExplorer As Outlook.Explorer
Dim oMail As MailItem
Set oExplorer = Application.ActiveExplorer
Set oMail = oExplorer.Selection.Item(1).Forward

On Error GoTo Release

If oExplorer.Selection.Item(1).Class = olMail Then
oMail.Subject = "FW: Personalized Subject Line"
oMail.HTMLBody = "Custom Text.<p> <img src=""custom image link""" _
& " title=""D"" alt=""D"" name=""D"" border=""0"" id=""D""/>" _
& vbCrLf & oMail.HTMLBody

oMail.Recipients.Add "xxx@xxx.com"
oMail.Recipients.Item(1).Resolve
If oMail.Recipients.Item(1).Resolved Then
oMail.Display
' oMail.Save
' oMail.Send
Else
MsgBox "Could not resolve " & oMail.Recipients.Item(1).address
End If
Else
MsgBox ("Not a mail item")
End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub
[/vba]

--
Lewis
 
Thread starter Similar threads Forum Replies Date
O Outlook tasks - Add text column with multiple lines Using Outlook 3
B Add Prefix text to Subject Line Using Outlook 1
e_a_g_l_e_p_i Is there a way to add something that is in the "Format Text" tab to the "basic Text" on the message tab Using Outlook 1
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
V Need to add some text in subject while creating new mails - NEED VB CODINGS Using Outlook 4
L Outlook 2007 Macro to Add Text to a Contact Field Using Outlook 10
F VBScript to add pre defined text Using Outlook 5
S Prompt to add for text to existing subject line before sending. Using Outlook 9
E Macro to add text to a Message Outlook VBA and Custom Forms 3
K 2003 Outlook Contacts - how do I add text to multiple contacts .... Outlook VBA and Custom Forms 2
U Outlook: Add memo text Outlook VBA and Custom Forms 4
W April 2020 Office 365 Update - Add-Ons fail after Office 365 Update Using Outlook 6
B Task Filter Not Working When I add too many criteria Using Outlook 0
D Add date next to day name in Outlook Today calendar view Using Outlook 1
D iCloud Add-in not working in Outlook 2013 and Outlook 2016 After Windows Upgrade & iCloud Upgrade Using Outlook 2
P Add Paste Unformatted to QAT Using Outlook 1
M Ignore slow add-ins Using Outlook 0
Jennifer Murphy Add birthdays to calendar Using Outlook 7
P Add, remove, & reorder folder pane Using Outlook 6
L Tired of Outlook disabling Adobe PDF Creator add-in Using Outlook 1
R Add 'Company' to Select Names Form Using Outlook 1
A Outlook 2016 Web add-in missing on some machines Using Outlook 9
P Syncing problems with add-ins Using Outlook 3
Mark Foley Cannot enable add-in in outlook 2010 Using Outlook 0
BretAB Is it possible to add a lookup field to a Message form? Outlook VBA and Custom Forms 4
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
iwshim outlook 2013 - I cannot see the "Manage Add-ins" Using Outlook 2
A Add multiple servers "on behalf of" email to "safe senders" list. Using Outlook 1
S Add Exchange Account as Secondary to Existing PST? Exchange Server Administration 1
C Macro to add multiple recipients to message Outlook VBA and Custom Forms 3
A Add to Outlook Contacts from email - default view Outlook VBA and Custom Forms 1
P Add a contact to the New Task in Outlook 2016 Using Outlook 2
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
O Outlook on Android - add BCC Using Outlook 2
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
B When I add more search strings to RULES, it is not processing them Using Outlook 3
D Add Tetxbox at form open Outlook VBA and Custom Forms 1
Andrew Quirl Open attachment, manipulate without add-on program? Outlook VBA and Custom Forms 5
B Searching for a Add-In Using Outlook 3
J Add Fillable Fields to Existing Template Outlook VBA and Custom Forms 1
J vb to c# for Outlook add-in. Using Outlook 0
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
R Outlook add-in to create new contact from an email. Using Outlook 0
twofivepie GTD Netcentrics add-in for 2016 Outlook VBA and Custom Forms 13
D Add all meeting rooms to the meeting request by default Outlook VBA and Custom Forms 0
A add birthday to outlook contacts Using Outlook 1
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
K add pdf to every reply or forward Outlook VBA and Custom Forms 1
Similar threads


















































Top