Solved

how to write a simple script in outlook 2007 to send one of a saved message in the draft folder to a particular recipient ?

Posted on 2008-10-14
6
2,549 Views
Last Modified: 2013-11-30
I want to send a particular saved message prepared in the draft folders to another outsider email recipient  when I receive a email from somebody.
I know using rules can provide conditional filtering but it seems the rules cannot allow me to send a saved draft message to outside.  Besides, I have a lot of draft messages and will be sent according to different recipient.

Can someone please help?

0
Comment
Question by:peteryau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 22710823
Hi, peteryau.

Here's the code for doing this.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on Module1
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comments wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10.  Close Outlook
11.  Start Outlook
12.  Create a rule
13.  Set the rule's action to "run a script"
14.  Select this script as the script to run

You can duplicate this code as many times as necessary to handle different rules.  You just need to change the name of the subroutine so it's unique and edit the subject text on line #5 of the code.
Sub DraftReply1(Item As Outlook.MailItem)
    Dim olkReply As Outlook.MailItem, olkDraft As Outlook.MailItem
    On Error Resume Next
    'Change the subject text on the following line'
    Set olkDraft = Session.GetDefaultFolder(olFolderDrafts).Items.Find("[Subject]='Some Subject'")
    On Error GoTo 0
    If TypeName(olkDraft) = "MailItem" Then
        Set olkReply = olkDraft.Copy
        olkReply.Recipients.Add Item.SenderEmailAddress
        olkReply.Send
    End If
    Set olkDraft = Nothing
    Set olkReply = Nothing
End Sub

Open in new window

0
 

Author Comment

by:peteryau
ID: 22714226
It works !!  but there some issues on
1) outlook prompt a dialogue everytime to manually click to allow access to the data, is there any setting I can do to get rid of it.  
2 ) Besides, the above code automatically also reply to the sender.  How can I change the code to only send to the defined recipient in the draft message in the draft folder? I don't need to reply to the sender.

Thank you for your help.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 22720459
Try removing line #9.  That will definitely fix item #2 and may fix #1 also.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:peteryau
ID: 22723630
Great !!!  10 out of 10 fast and accurate. I appreciate.  Thank you very much.
By the way, I am sort out other small macros in outlook which I think may need your help again...
0
 

Author Closing Comment

by:peteryau
ID: 31505847
You are so great!!! Thank you. BTW, I am sorting out other macros I need in outlook automation.   I probably need your help again.  I will post it later.
Thanks again.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22723813
Thanks and you're welcome.  If you ever want to draw my attention to a question, then you're welcome to send me an email with a link to the question.  My address is in my profile.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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