Autoforward Outlook emails to external only under certain circumstances

0

Is there a modification that can be made to the VBA code provided in this response from an earlier post that would only forward email from a certain email address rather than forwarding everything? Essentially, mimicking an outlook autoforward rule with a condition that only messages from email@email.com get sent?

I have written some VBA script to do this *bypass the server's disabling of auto-forward". Basically it mimics the user forwarding the email rather than the server doing an auto-forward. It's beyond the scope of this post to give detailed instructions, but here's a summary:

Add the above code in the Visual Basic editor of Outlook (Alt-F11 should get your started). Be sure to change email@email.com to the address where you want the mail to go

Tell Outlook to run this code for each inbound message (Tools -> Rules and Alerts -> New Rule -> Check Messages when they arrive -> Next -> YES -> Checkbox "Run a Script" -> Then select the script you just created.

Now Outlook should automatically forward each email you receive, but it won't be blocked by the Admin as an "Auto-forward".

Code:

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

Set myFwd = Item.Forward

myFwd.Recipients.Add "email@email.com"
myFwd.Send
Set myFwd = Nothing 
End Sub

Doug

Posted 2014-03-03T20:36:41.687

Reputation: 1

Answers

1

Try adding an if statement using the sender address -

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

Set myFwd = Item.Forward

If myFwd.Sender = "sender@email.com" then
myFwd.Recipients.Add "email@email.com"
myFwd.Send
End if

Set myFwd = Nothing 
End Sub

Or, the easier way, would be in setting the rule:

Tell Outlook to run this code for each inbound message (Tools -> Rules and Alerts -> New Rule -> Check Messages when they arrive -> Next -> YES -> Checkbox "Run a Script" -> Then select the script you just created.

Just tell outlook to run the code if the message is from a certain address.

Raystafarian

Posted 2014-03-03T20:36:41.687

Reputation: 20 384