Turning a rule on with a text message & message alerts

Status
Not open for further replies.
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:

somebody@somewhere.com".

Please let me know if you can help me out.

Thanks Again,

Mike

"Mike Waters" wrote:


> 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.
 
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.

Sue Mosher

"Mike Waters" <MikeWaters> wrote in message

news:9A9D46DE-EF1F-4F19-B538-5051246F9F5F@microsoft.com...
> 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:
> somebody@somewhere.com".

> Please let me know if you can help me out.

> Thanks Again,

> Mike

> "Mike Waters" wrote:
>
> > 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.
 
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.

"Mike Waters" <MikeWaters> wrote in message

news:9A9D46DE-EF1F-4F19-B538-5051246F9F5F@microsoft.com...
> 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:
> somebody@somewhere.com".

> Please let me know if you can help me out.

> Thanks Again,

> Mike
 
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
wrote:


> 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.

> >

>

> "Mike Waters" <MikeWaters> wrote in message
> news:9A9D46DE-EF1F-4F19-B538-5051246F9F5F@microsoft.com...
> >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:
> > somebody@somewhere.com".
> > Please let me know if you can help me out.
> > Thanks Again,
> > 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.

"Mike Waters" <MikeWaters> wrote in message

news:D07F1B83-7533-44E4-8B08-3A23241AD3C1@microsoft.com...
> 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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Turning on/off Rules from VBA Using Outlook 2
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
B Modify VBA to create a RULE to block multiple messages Outlook VBA and Custom Forms 0
D VBA - unable to set rule condition 'on this computer only' Outlook VBA and Custom Forms 5
CWM330 This rule has a condition that the server cannot process? Using Outlook 1
A rule name into message - how? Outlook VBA and Custom Forms 5
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
bhamberg Finding a rouge rule... Using Outlook 6
D How to get this rule to work Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Save attachment run a script rule Outlook VBA and Custom Forms 0
R Rogue Outlook Rule ? Using Outlook 2
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
1 Incorrectly Setup a Rule at Domain level to not allow address from outside domain Exchange Server Administration 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
T "Words In Recipient's Address" Rule Causes Outlook To Stop Processing Rules Using Outlook 3
R Outlook Autoforward rule do not work for NDR messages Using Outlook 1
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
N Rule for "on behalf of" - with changing names Using Outlook 2
S Unable to remove rule outlook 2010 Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
S Adding new Exchange (2016) rule very slow down Microsoft Outlook Exchange Server Administration 0
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
icacream Rule based on sender / wrong sender sent to folder Using Outlook 7
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
L Making rule to move email to folder from one O365 domain Using Outlook 1
J Assess content of User Defined Field in Rule Using Outlook 3
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
A Change order of actions in one (!) rule Outlook VBA and Custom Forms 2
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
A rule to flag messages not working Using Outlook 5
Brian Murphy Exchange Online Everything a Transport Rule should do and cannot Exchange Server Administration 1
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0
A saving attachement to folder named the same as rule name Outlook VBA and Custom Forms 0
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
A Rules - how to determine if all conditions in rule are true or false Outlook VBA and Custom Forms 5
Vijay Error in rule- Run a script Using Outlook 1

Similar threads

Back
Top