3
votes

I am trying to run a rule in outlook that will forward any new mail that comes into a specific account that will change the subject line and forward the mail to a different account.

I have set up a rule that applies the rule after the message has arrived, which has an attachment, and on this machine only run Project1.ThisOutlookSession.SubjForward except if message body contain 'certain text'

The script looks like this

Sub SubjForward(Item As Outlook.MailItem)

Item.Subject = "New Subject"
Item.Save

Set myForward = Item.Forward
myForward.Recipients.Add "[email protected]"

myForward.DeleteAfterSubmit = True

myForward.Send

End Sub

The rule forwards the message to the new address fine but it keeps on forwarding the same email until I kill the script.

Dose anyone know where I am going wrong?

I have updated further details in the comments below, thanks

1
I can't see any obvious reason from your code, you could look at checking the item is "Unread" before forwarding and then mark it as "Read" at the end of the sub so that it doesn't get picked up again. - Matt Donnan
Do you have any other defaults setup within Outlook? (i.e. CC yourself on all messages, etc.) - Gaffi
Is that Different Account also configured with same outlook? - Siddharth Rout
Matt, thanks I will try that, altough I cant see why it would be necessary. Gaffi, no other defaults that would suggest multiple forwarding would occur that I can see. Siddharth, the different account is a gmail account but is not conifgured with my outlook. The mail gets sent to the my Personal Folders -> Outbox folder and then gets sent but the mail then keeps getting put into that outbox folder and sent over and over again. - Henrick
I stripped back the script to just Sub ChangeSubjectForward(Item As Outlook.MailItem) Item.Subject = "Test 9" Set myForward = Item.Forward myForward.Recipients.Add "[email protected]" myForward.Send end Sub . It works fine except when coming from a gmail account (yahoo,hotmail etc work fine). The account using outlook to auto forward the mail is also a gmail account. So it appears gmail to gmail is causing a problem. The mail comes in to the inbox, forwards to the outbox then disappears from the inbox and repeats until script is killed - Henrick

1 Answers

0
votes

Try using the ItemAdd Event handler, this way your script will only run when a new 'item' is added to your inbox ie. when you receive the mail.

Alternatively, I cannot see a need to use VBA at all really here? You could just set up a rule on outlook to forward the message?

Regards Paul