Solved

How to create VB Program that automatically forwards Outlook email

Posted on 2004-10-21
252 Views
Last Modified: 2012-05-05
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
Question by:ChWCIT
    4 Comments
     
    LVL 16

    Accepted Solution

    by:
    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
     

    Author Comment

    by:ChWCIT
    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
     

    Author Comment

    by:ChWCIT
    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
     
    LVL 16

    Expert Comment

    by:jimbobmcgee
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now