Turning a rule on with a text message & message alerts

  • Thread starter Thread starter Mike Waters
  • Start date Start date
M

Mike Waters

Hello,

I am looking for a way to create three rules. The first two kind of go
together. The one would be a rule that would turn on other rules when I send
a text message from my phone. The reason I am looking to do this is I can't
access the e-mail address I need from my cellphone, but can access a gmail
account. So I would like to be able to turn on a rule that will forward
certain e-mails to my gmail account when I send a text message.

Basically what I would like that rule to look for is an e-mail from (my
cellphone number)@(my carrier).net with the work on in the body, then turn on
a rule called Work. This work rule I would like to have do two things. The
first part is the easy part. And that is to forward e-mails from certain
people to my gmail account. The hard part then, for me at least, is to then
have it send an email/text message to my phone to tell me that there is an
e-mail waiting. So that is what I would like the second script to do, create
an e-mail that would be sent to my phone that basically would say, "You've
got mail."

The third script then would be one that would turn off the work rule. So
that this one would look for an e-mail with the word off in the body that
comes from my cellphone, and this would turn the rule back off then. Any
help would be great.
 
I was able to create a script that would send a message to my cellphone. I
have the following script:

Sub txtmsg()
Dim position As Long
Dim OLobj As Object
Dim Mailobj As Object
Dim BodyStr As String
Dim SectStr As String


Set OLobj = CreateObject("Outlook.Application")
Set Mailobj = OLobj.CreateItem(olMailItem)
With Mailobj
..To = "(My Cellphone)@(my provider).net"
..Body = "You've Got Mail"
..Send
End With

Set Mailobj = Nothing
Set OLobj = Nothing


End Sub

The problem I seem to have now is I can't get it to run from a rule. When I
go to the run script option, its not shown.

The other question I have for this script is when an e-mail comes in that
fits the rule that it will run from, is there a way to get the sender
information from that e-mail, and add it to the body of the text message that
goes to my phone. So it would say something like, "You've got mail from:
(e-mail address removed)".

Please let me know if you can help me out.

Thanks Again,

Mike
 
A "run a script" rule action to operate on messages needs a MailItem as its
argument. That item is processed by the code:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.Session
Set msg = olNS.GetItemFromID(strID)
' do stuff with incoming msg, e.g.
strAddress = msg.SenderEmailAddress
Set Mailobj = Application.CreateItem(olMailItem)
With Mailobj
.To = "(My Cellphone)@(my provider).net"
.Body = "You've Got Mail from " & strAddress
.Send
End With

Set Mailobj = Nothing
Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

For Outlook VBA basics, see http://outlookcode.com/article.aspx?id=49

For another example of a "run a script" rule actions, see:

http://www.outlookcode.com/codedetail.aspx?id=1494

CAUTION: Using this technique has been known to result in corrupt VBA code.
Be sure to export your code modules or back up the VBAProject.otm file.
 
2 things wrong with your code.

First in Outlook VBA never, ever use CreateObject() or New or whatever to
get an Outlook.Application object, use the intrinsic trusted Application
object.

Second the signature of your method is incorrect. It should have an Item As
Outlook.MailItem argument passed to it:

Public Sub txtmsg(Item As Outlook.MailItem)

With the correct signature you will have the information you were asking
about for the original message that triggered the rule.
 
Thanks for the help. I updated the text message part of the code to show
what you suggested, and it works great. Now I just need to figure out how to
do a redirect with the script. I can tell it to forward using commands in
the rule, but since I'm not using an exchange server I don't have the
redirect option. I tried the following code for this:

Dim OLobj As Object
Dim Mailobj As Object
Dim BodyStr As String
Dim SectStr As String
Dim SenderStr As String

Set OLobj = CreateObject("Outlook.Application")
Set Mailobj = OLobj.CreateItem(olMailItem)
BodyStr = MyMail.Body
SenderStr = MyMail.SenderEmailAddress
With Mailobj
..SentOnBehalfOfName = SenderStr
..To = "(redirect account)@someplace.com"
..Body = BodyStr
..Send
End With

This part seems to create a new e-mail message to send, but I get an error
back right away in my inbox saying:

550 5.7.0 From address mismatch: envelope <my email address> and header
<forwarding e-mail address>

Any help on this would be great.

Thanks,

Mike
 
Please read what I wrote before:

First in Outlook VBA never, ever use CreateObject() or New or whatever to
get an Outlook.Application object, use the intrinsic trusted Application
object.

You cannot just set a sent on behalf of to some arbritrary address that's
not yours in a mail you create. Having or not having Exchange has nothing to
do with that. Forward the message or send the new one.
 
Back
Top