Add text to auto-forwarded e-mail

Status
Not open for further replies.

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!
 
you will need to use a macro - I have an example here -
 
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?
 
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
 
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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker Add a text line at the end of the note field in all selected Contacts Outlook VBA and Custom Forms 7
L did MS ever add way to text via Outlook Using Outlook 5
BartH Add a string to the conditions in .Conditions.BodyOrSubject.Text Outlook VBA and Custom Forms 2
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
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
G Outlook 2021 Add Picture to Custom Contact Form Outlook VBA and Custom Forms 2
P Can't add custom field to custom Outlook form, it always adds to the Folder instead Outlook VBA and Custom Forms 2
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
S Outlook 2019 Custom outlook Add-in using Visual Studio Outlook VBA and Custom Forms 0
G automatically choosing "add to autocorrect" option Using Outlook 0
F Want to add second email to Outlook for business use Using Outlook 4
K Add an entry to a specific calendar Using Outlook 1
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
J Outlook 365 Add keywords from Listbox to the message body where cursor is placed Outlook VBA and Custom Forms 0
O Add Day Number of the year for 2023-2033 Outlook VBA and Custom Forms 5
J GoDaddy migrated to Office365 - Outlook Wont Add Account Exchange Server Administration 21
F Outlook 2019 Outlook 2019 Add and Sync to New computer Comcast server Using Outlook 2
A iCloud Outlook Add In is causing Outlook 2021 to crash and got disabled Using Outlook 10
N How to add or delete items to Move dropdown Menu Using Outlook 0
G Add contacts birthday to calendar Using Outlook 4
V How to add 'Previous Item' and 'Next Item' to the Quick Access Toolbar Using Outlook 1
Commodore Safe way to add or update holidays; Windows Notifications issue Using Outlook 8
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
P How to add a column named categories when searching in Outlook Using Outlook 0
M add new attendee to existing meetings with VBA Outlook VBA and Custom Forms 5
N Can't create NEW GROUP and add/remove a member from existing Group in Outlook Using Outlook 1
Witzker Outlook 2019 Pls. add a Prefix for OUTLOOK 2019 here Using Outlook 1
P Add inanimate objects to meetings? Using Outlook 1
O Outlook 2010 Add delete button to the side of the message list Using Outlook 1
A "Get Add-Ins" - Which Version of Outlook to use Using Outlook 1
D Do I need Exchange Add-In? Using Outlook 6
C-S-R Manage Add-ins (Remove Wunderlist) Using Outlook 6
A iCloud add in problems Using Outlook 4
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
C Looking for feedback on new Outlook Add-in Using Outlook 0
L isn't there an OL add-on that flags addressee before sending Using Outlook 3
S Add VBA save code Using Outlook 0
P Shortcut Pane - add shortcut to Office365 group mailbox Using Outlook 1

Similar threads

Back
Top