Announcement

Collapse
No announcement yet.

Script to Parse Content on Email

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    I updated post #13
    Let me know if it works
    -Rupp
    sigpic

    Comment


      #17
      I tried several keywords and items that should fail and it worked fine each time. So I think it is Okay now to say >>>>

      Originally posted by pp
      Ding Ding Ding We got a winner!
      Seemed to work fine. GOing to try a few more but I think that's it..
      Thank YOUUUUUUUUUUUUUUUUU!

      Comment


        #18
        Anyone following this thread or wants to parse an email to trigger events there are 2 ways of doing this. Rupps Scripts works great and is quick and easy. Option 2 is Jon00 CheckEmailpop. V3 (Needs a Tweak to the Checkemailpoptrigger.vb and enable the script in the .ini file.)it has the ability to go into your email server and parse the email and check multiple emails and keywords. So just a follow up.

        Comment


          #19
          I spent some time tweaking this code and came up with some modifications based on my own use case. I wanted to be able to trigger events from my cellular phone via text messaging. Nothing complicated really, I just wanted to be able to send a msg to turn off lights or turn on the porch light etc.

          I have this working for my own use case so feel free to modify it however. It supports two methods direct X10 command or event triggers.

          example - send email with the following subject line
          1234 cmd a1 on


          1234 - that's the password so you don't accidentally get spurious commands from spammers or by mistake etc.

          cmd - designates this as X10

          That will send hs.execX10 "a1", "on"

          The other example is for event triggers
          1234 event good night

          1234 - password
          event - designates it as event trigger
          "good night" is the event name

          Here's the code
          *I changed it right after first posting I found hs.triggerEvent(trim(cEventName))
          worked better for the trigger since leading or trailing spaces were messing me up
          Attached Files
          Last edited by grauchy; February 26, 2007, 05:21 AM. Reason: Fixed bug in script. Changed trigger to hs.triggerEvent(trim(cEventName))

          Comment


            #20
            email triggers

            Testing out the email search version

            What does HS have to be config. Do I have to set with event email trigger condition, email checked by HS,

            I.e. ??

            Edit email Received Trigger

            EMAIL received from the following address will trigger the event:

            EMAIL from anyone causes trigger

            I have tested some different variations but no luck yet.

            Thanks.
            HS3 Standard Edition 3.0.0.258

            Comment


              #21
              Basically yes. I have had trouble getting hs.mailsubject hs.mailtext to work in the last few hs releases.

              Comment


                #22
                Originally posted by basshook View Post
                Basically yes. I have had trouble getting hs.mailsubject hs.mailtext to work in the last few hs releases.
                What verson of HS are you running? I'm using the release version and it's working fine.
                -Rupp
                sigpic

                Comment


                  #23
                  Rupp,

                  I am trying to use the script you provided here. I get this error in my log when it runs.

                  Getting email body: Collection index must be in the range 1 to the size of the collection.

                  any ideas?

                  Ian
                  Plugins:
                  BLLogMonitor, BLGarbage, BLBackup, BLOutGoingCalls, BLUps, BLRfid, JvEss, DooMotion, Applied Digital Ocelot, AC RF Processor, UltraMon, PJC AVR 430, UPB, Rain8net, DSC Panel, JRiver Media center, Windows Media Player, SageMediaCenter, SnevlCID, MCSTemperature.

                  Comment


                    #24
                    This is modified from what I use for Fox News:

                    PHP Code:
                    sub main()

                    dim index subject body

                    index 
                    hs.MailTrigger 
                    subject 
                    hs.MailSubject(index)
                    body hs.MailText(index)

                    end_hook instr(body,"Replies to this message") -' Trims off the stuff you don't want at the bottom of the email.
                    if 
                    end_hook 10 then end_hook len(body
                    body left(body,end_hook)
                    body Replace (body"Sch. Dist.""School District",1,-1,1)
                    hs.WriteLog "Ridgefield School Alert" body

                    'Fill in whatever actions you want
                    '
                    hs.speak "Email from Ridgefield Schools:" body

                    end sub 
                    To trigger this event you must use an email trigger from info@flashalert.net

                    To test it you must use an email trigger from your-email and send your HS a copy of the email the school sends you.

                    That's it for today, I'm home sick and my head is pounding, good luck.


                    ~Bill

                    Comment


                      #25
                      What email are you trying to parse and I'll have a look.
                      -Rupp
                      sigpic

                      Comment


                        #26
                        Originally posted by Rupp View Post
                        What email are you trying to parse and I'll have a look.
                        I think this is what he wants parsed:


                        ---------- Forwarded message ----------
                        From: <info@flashalert.net>
                        Date: Mon, Dec 15, 2008 at 5:10 AM
                        Subject: [FlashAlert] Emergency Info - MON, Dec. 15 - 05:12
                        To: ian@xxx.org, smaxxxxife@yahoo.com, xxxxxxx@tmomail.net


                        Ridgefield Sch. Dist.: 2 hrs late

                        Replies to this message do not go back to the sender.
                        To add, change or delete these messages, go to http://flashalert.net/login.html


                        ~Bill

                        Comment


                          #27
                          Ian,
                          Can you send me one if the actual emails to greg@homeSeer.com so I be sure to get this correct.
                          -Rupp
                          sigpic

                          Comment


                            #28
                            just sent, thanks!
                            Plugins:
                            BLLogMonitor, BLGarbage, BLBackup, BLOutGoingCalls, BLUps, BLRfid, JvEss, DooMotion, Applied Digital Ocelot, AC RF Processor, UltraMon, PJC AVR 430, UPB, Rain8net, DSC Panel, JRiver Media center, Windows Media Player, SageMediaCenter, SnevlCID, MCSTemperature.

                            Comment


                              #29
                              Ian,
                              Try this.

                              Code:
                              CONST cEmailAddress = "info@flashalert.net"
                              CONST cSearchString = "Ridgefield Sch. Dist"
                              CONST sDebug = True
                              sub main()
                              	index = hs.MailTrigger
                              	sMailFrom = hs.MailFrom(index)
                              	sSubject = hs.MailSubject(index)
                                      sBody = hs.MailText(index)
                              	sStatus = fParseMail(sMailFrom, sBody)
                              	hs.writelog "email_parser", sStatus
                              	
                              end sub
                              
                              function fParseMail(sMailFrom, sBody)
                                
                                  if lcase(sMailFrom) = lcase(cEmailAddress) then
                              	sStart= instr(1,lcase(sBody),lcase(cSearchString)) 
                                      if sStart > 0 then 
                                              sEnd = instr(sStart, lcase(sBody), "replies")
                                              if sDebug then hs.writelog "info", "sStart = " & sStart
                                              if sDebug then hs.writelog "info", "sEnd = " & sEnd
                                              sData = mid(lcase(sBody),sStart , sEnd - sStart) 'sEnd - sStart
                                              if sDebug then hs.writelog "info", "sData = " & sData
                              		fParseMail = "Success"
                              		hs.speak sData
                              	else
                              		fParseMail = "Failed"
                              	end if
                                  end if
                              You can set sDebug to False once you get it running.
                              -Rupp
                              sigpic

                              Comment

                              Working...
                              X