Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to create VB Program that automatically forwards Outlook email

Posted on 2004-10-21
4
Medium Priority
?
256 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
Comment
Question by:ChWCIT
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 2000 total points
ID: 12369527
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
ID: 12369739
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
ID: 12369859
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
ID: 12370874
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

579 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