Solved

Using VBS to forward an email

Posted on 2004-04-13
7
872 Views
Last Modified: 2007-12-19
Hello everyone!

I'm trying to do something here and I'm not a VBS expert.  Hope someone can lead me in the right direction.

I need a VBS or some sort of macro for Outlook 2002/Exchange 2k that will forward an email to a specified address and put a one word command in the body of the message.  

We have a mailbox that our users forward spam to and then we forward it to our spam filter.  Great spam filter huh?

Thanks in advance for everyone's help.

0
Comment
Question by:rchandler6473
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:rosesolutions1
ID: 10818596
Lots of ways - before we all give you options, can you answer these 2 questions?

How do you want to trigger this code?
(a) Automatically, say using Outlook rules
(b) Manually, via a button on the toolbar

Do you need to deploy it to lots of workstations (ie. need it to be installable), or only a few (ie. could do it manually on each one)?
0
 

Author Comment

by:rchandler6473
ID: 10818672
I think I want to do it automatically using the rules.  This will only be run on two workstations and if necessary can be run manually.  Right now I have one of my technicians forwarding them manually and it takes quite a long time to forward 900+ messages a day.  Rules won't quite cut it by themselves due to it not being able to put something in the body of the message.

Hope this is what your asking.

Thanks!
0
 
LVL 7

Accepted Solution

by:
rosesolutions1 earned 125 total points
ID: 10818785
OK
Step 1: Create the Code
Open the VBA editor for Outlook (Alt-F11). By default, Project1 will be selected and there will be a big blank window ready for code. Paste the following into it:

Sub FwdToMe(Item As Outlook.MailItem)
    Set myitem = Item.Forward
    myitem.Recipients.Add "PUT YOUR EMAIL ADDRESS HERE"
    myitem.Body = "WHATEVER TEXT YOU WANT TO INSERT" & vbCrLf & vbCrLf & myitem.Body
    myitem.Send
End Sub

(the vbCrLfs are carriage returns - put more or less as suites you.)

Click File/Save

Step 2: Connect to a rule
Create an Outlook rule, with the action as "Run a script" - select the only one you have (which will say something Project1.ThisOutlookSession.FwdToMe).

Done.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:rchandler6473
ID: 10821828
I got it to work once, but after that it no longer works and I get a error saying the operation failed almost immediately.  Also, when the VBA editor comes up it doesn't have a window to post code into.  I have to tell it to insert something so I chose a module.

Gettting close though.
0
 
LVL 7

Expert Comment

by:rosesolutions1
ID: 10822935
Thats odd. Put the code in the module then - it will still work.
0
 

Author Comment

by:rchandler6473
ID: 10823036
With a slight modification of the code I got it to work.

Sub FwdToMe(Item As Outlook.MailItem)
    Dim myitem As Outlook.MailItem
    Dim address As String
    Set myitem = Item.Forward
    address = "email address"
    myitem.Recipients.Add address
    myitem.Body = "WHATEVER TEXT YOU WANT TO INSERT" & vbCrLf & vbCrLf & myitem.Body
    myitem.Send
End Sub

Only other problem that I'm having is the Outlook security feature.  It pops up every message and asks if it can have access to it.  I read something on the board about a program called redemption that can bypass the security.  I'll take a look at that.
Any suggestions to fix that little security problem?
0
 
LVL 13

Expert Comment

by:stefri
ID: 10850824
Even if the question is PAQ, a little follow up:
Download redemption from:
Dowload an install Redemption http://www.dimastr.com/redemption/download.htm 
Read the docs: http://www.dimastr.com/redemption/objects.htm then

Sub FwdToMe(Item As Outlook.MailItem)
    Dim myitem As Outlook.MailItem, SafeItem as Object
    Dim address As String
    set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
    Set myitem = Item.Forward
    SafeItem = myItem
    address = "email address"
    SafeItem.Recipients.Add address
    SafeItem.Body = "WHATEVER TEXT YOU WANT TO INSERT" & vbCrLf & vbCrLf & myitem.Body
    SafeItem.Send
    set SafeItem = nothing
End Sub

would solve the security problem
Stefri
0

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.

Question has a verified solution.

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

Outlook Free & Paid Tools
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

821 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