Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am using below command to automatically forward email.

I'm having trouble with automatically forward email.

Please help me with a few questions below

1. Outgoing email address
Currently: can only send 1 email
Desire: send to many different emails

2. Email content
Currently: no email content yet
Desired: add a command about email content including ( title mail + any content )

Thanks for helping me.

Sub AutoForwardAllSentItems(Item As Outlook.MailItem)
Dim strMsg As String
Dim myFwd As Outlook.MailItem

Set myFwd = Item.Forward

myFwd.Recipients.Add "xxx@xxx.com"

myFwd.Send
Set myFwd = Nothing
End Sub


What I have tried:

Sub AutoForwardAllSentItems(Item As Outlook.MailItem)
Dim strMsg As String
Dim myFwd As Outlook.MailItem

Set myFwd = Item.Forward

myFwd.Recipients.Add "xxx@xxx.com; xxx@xxx.com; xxx@xxx.com"
xStr = "<p>" & "Hi, Your email has been received. Thank you!" & "</p>"
myFwd.HTMLBody = xStr & .HTMLBody

myFwd.Send
Set myFwd = Nothing
End Sub
Posted
Updated 18-Nov-21 5:34am

Point 1 - you need to call the forwarding code for all the items in the relevant folder - E.G. See vba - Outlook VBscript to forward emails in a folder[^] (but there are literally thousands of examples to find)
Point 2 - you already have the code to add "content" to the email
VB
xStr = "<p>" & "Hi, Your email has been received. Thank you!" & "</p>"
myFwd.HTMLBody = xStr & .HTMLBody
 
Share this answer
 
Comments
Maciej Los 18-Nov-21 16:59pm    
5ed!
- First, go ahead and open Microsoft Outlook.
- Hit File then select Options
- Now go ahead and select Customize Ribbon.
- In the Customize Ribbon section, you’ll notice the Choose Commands from the list box.
- Select Macros
- Then Select your newly created VBA code, in our case, the name should be SendMail.
- Then hit Add and then OK. Optionally you might want to assign an icon to your Macro.
- Your Macro will be available in the Quick Access toolbar on the upper left side of your Outlook application.

Regards,
Peter
 
Share this answer
 
Comments
CHill60 14-Dec-22 3:23am    
In what way does any of this help the OP with their question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900