Selective Mail announce


Senior Member

Next topic...

How do you have Homeseer announce incoming mail from, and the subject (I already have this)

EXCEPT from a particular address?

I was trying something like this:
sub main()
	dim index
	dim subject
	dim contents
	dim MsgFrom
	index = hs.MailTrigger

	subject = hs.MailSubject(index)

	from = hs.MailFrom(index)

	contents = hs.mailtext(index)

if From = "[email protected]" then
system.speak ""

	system.speak "You have mail, from, " & from & ". The subject is," & subject
	'system.speak "text is as follows, " & contents
	end if
end sub

But it does not work.

I usually use a statemnet like this:

if instr(lcase(from),"sbessel") then exit sub

Clean, and easy one line. I always check my strings to either upper or lower case just to make sure.
Actually, Ski, your code should work, but it will have to EXACTLY match the incoming email address, including the case of the letters. There are functions that allow you to make everything upper or lower case to make the comparison a bit easier. The INSTR works well as long as you use a string unique enough to match only the ones you wish to filter.
Skibum said:
If you do that, will the event still read the rest of the mail?
Yes as the event only fires on each individual email message. So the script runs once per message. The 'exit sub' statement would essentially just skip the current message and move on the next if there are more.

You could easily replace the 'If' clause and replace with my single line statement. And the example I gave would work well if you used the last name or such, as the from field changes depending on email source and computer that sent it.
OK... what is happening, is that when new mail arrives from [email protected], the script is still reading an old email from [email protected], and not the new one. what I need to do is delete the message right after the script runs, so the next message that arrives will be the only one from [email protected]

sub main()

dim MyArray, MsgIndex, MsgSubject, MsgFrom, MsgText

MsgIndex = hs.MailTrigger
MsgSubject = hs.MailSubject(MsgIndex)
MsgFrom = hs.MailFrom(MsgIndex)

if MsgFrom = "[email protected]" then

 MsgText = hs.MailText(MsgIndex)

MyArray = split(MsgText, ".", -1, 1)

 hs.SetDeviceString ("y40"), MyArray(0),true
 hs.SetDeviceLastChange ("y40"), now
 hs.SetDeviceStatus ("y40"), 2

end if

end sub
What are you using to trigger this script?

What method are you using for email, POP3 or Outlook?
... well that explains a lot, first set your event to trigger on new messages from anyone, then let the script deal with the who. I am not sure with outlook, but with the POP3 interface, if HS has already read the message it will leave it on the server but will not consider it new again or read it again.