Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How to create VB Program that automatically forwards Outlook email

Does anyone have a Visual Basic script that will automatically check all new Outlook email for a certain keywords (ie. "you", or "help"), remove any attachments from the email, and forward just the body of the email to another email address?  Thanks in advance.
0
ChWCIT
Asked:
ChWCIT
  • 2
  • 2
1 Solution
 
jimbobmcgeeCommented:
The following should be placed in a module in your Outlook macros:

    Sub StripAndForward(thisMail As Outlook.MailItem)
   
        Const strAddress    As String = "somebody@somewhere.com"
                                                'FORWARDING ADDRESS
        Const blnAutoSend   As Boolean = False  'SEND FORWARD AUTOMATICALLY
   
        Dim objFwd As Outlook.MailItem
        Dim objAtt As Outlook.Attachment
       
        For Each objAtt In thisMail.Attachments
            objAtt.Delete                       'DELETE EACH ATTACHMENT
        Next objAtt
       
        Set objFwd = thisMail.Forward           'CREATE FORWARD MAIL
       
        objFwd.Recipients.Add strAddress        'ADD RECIPIENT
       
        If blnAutoSend = True Then objFwd.Send Else objFwd.Display
                                                'AUTOSEND OR DISPLAY
       
        Set objFwd = Nothing
        Set objAtt = Nothing
        Set thisMail = Nothing                  'CLEANUP
       
    End Sub

You can now set a message rule to search for the words you want to filter from the subject or body, telling the rule to run a custom script if those words are found.

HTH

J.
0
 
ChWCITAuthor Commented:
jimbobmcgee,
I set up the module and created a rule to run that script when the keywords are found.  It seems to be running the script, however the emails are never received at the new address.  I have tried to with several addresses .
0
 
ChWCITAuthor Commented:
Nver mind jimbobmcgee, it is working now.  i had to change

Const blnAutoSend   As Boolean = False  'SEND FORWARD AUTOMATICALLY

to

Const blnAutoSend   As Boolean = True  'SEND FORWARD AUTOMATICALLY

Thanks for the help.
0
 
jimbobmcgeeCommented:
No problem, ChWCIT

I put that blnAutoSend line in so you can check the mail looks correct befrore you send it.  Its a debug thing...

Thanks for the points; glad to help!!

J.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now