Check Email Question

I performed a search for “check email” but nothing came up.

I’m sure this topic has been done to death but I’m new to it.

Is there a way to do all of this WITHOUT opening up a program? (Do this completely within the script?)

  1. Check for new email on a server
  2. If new mail is present, check it’s from, to and subject information (all three)
  3. Delete a message based on information from 2

I need for all three of these issues to be covered.

One example for why I’m doing this is so that if I get a message from an outside service saying “you have new mail waiting for you on our outside service’s page, please log in to view the message” … my applescript would then delete their notification and open up my web browser, taking me directly to their login screen automatically (this would in turn serve as my notification that an email is waiting there).

That’s only one example. Really, I just need assistance with steps 1, 2 and 3 so that I may implement the result myself.

It is possible, but not trivial; there is a mail program (called MAIL) that can be run from the terminal, and thus from a “do shell script” construct in AppleScript. It can both send and receive emails. If you look at man mail, you’ll see that it can do all the things you mention.