# [SOLVED] Outlook Rule -- Send a Message!



## TPSMono30 (Jun 18, 2009)

What I'm trying to do is create a rule to send an email whenever certain emails arrive. I do not want to forward or redirect the original, just a notice sent letting me know I have mail. The reason is I would like to get an SMS alert when certain emails land in my box. I don't want the whole email since they can be quite long and I don't plan on reading them on my phone anyway. 

I searched high and low but I can't find anything even hinting at a possible solution. Any ideas?

Thanks!


----------



## TPSMono30 (Jun 18, 2009)

*Re: Outlook Rule -- Send a Message!*

I found a solution that works well for me. It uses a script so it has to be a client side rule. 
First, I started with the script provided at:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6480

I modified it a little bit and ended up with this:

```
Sub SendRuleMail(objItem As Outlook.MailItem)
    Dim objMail
    Dim strMsg
    
    'Create a message object
    Set objOutlk = CreateObject("Outlook.Application")
    Set objMail = objOutlk.CreateItem(0)
    
    'Create a new message
    objMail.To = "<PhoneNumber>@txt.att.net"
    objMail.CC = "" 'Enter an address here To include a carbon copy; bcc is For blind carbon copy's
    
    'Set up Subject Line
    objMail.Subject = "New mail"
    
    'Add the body
    strMsg = objItem.Subject 'I used the subject of the new mail for the body
    objMail.Body = strMsg
    objMail.Send
    
    'Clean up
    Set objMail = Nothing
    Set strMsg = Nothing
    Set objOutlk = Nothing
End Sub
```
I then went into Tools->Macro->Visual Basic Editor and opened the "ThisOutlookSession" object. I pasted the code above into it and it automatically added the Subroutine's name. I hit save and the subroutine now shows up in the Rules Wizard when I choose to run a script. 
I also had to disable the security window in Tools->Trust Center->Programmatic Acces->"Never warn me..." which is a little risky I guess. I'm sure this code can be optimized a bit, but it works for me! Since everything is hard coded in, a new script needs to be made if you want a different destination/subject/message for different types of emails. For example, I copypasta'd the working sub and renamed it SendRuleMailUrgent. In that Sub, I just changed the subject and body to read "URGENT" and I made a new rule to call that sub when the subject line has "Urgent" except when the subject has "RE: ". A couple of items to note that I found through my research:
* The Sub must accept an object of type Outlook.MailItem or Outlook.MeetingItem since that is what is passed when the rule is activated. I did not test it without that parameter, so I'm not sure what would happen, if anything.
* Someone noted that you should select "Stop processing rules" at the end of any rule that uses a VB script for some reason. I included it in my rules to prevent any possible issues with other rules.
(http://www.outlookcode.com/article.aspx?id=62)
* Outlook needs to be running of course! (Client side rule)

Not sure if anyone is interested in this, but I posted the solution in case I ever forget how to do this. :grin:


----------

