开发者

How to implement a script that listens for new mail and then perform an action

I have an apache James mail server setup and I would like to create a script that will listen for new mail and then communicate with an Asterisk server to call a user phone number and read the message. I assume this is possible but cannot find any information. I have been using perl scripting for other tasks so if I could do this with p开发者_运维知识库erl that would be great.

Thanks in advance


A solution would be to set up a cron job to run a perl script that uses something like Mail::POP3Client to check for new messages and sends something to Asterisk using (maybe) Asterisk::AGI. If the CPAN modules don't do what you need, you can always have the perl script execute system calls to interface with command-line tools that are capable of checking POP or interfacing with Asterisk.


I guess the best way to do that is to write a Mailet in java and put it in configuration to make it listen for the all mails in the root processor.

For Apache James 3.0-beta5 steps would be something like this:

  1. Write the Mailet i.e:

    import org.apache.mailet.*;
    public class myMailet extends GenericMailet {
      private String aParameter;
      @Override
      public void init(MailetConfig cfg) throws MessagingException {
        super.init(cfg);
        aParameter = getInitParameter("myNeatParameter"); // use this if you need to use some parameters specified inside the mailetcontainer.xml
      }
    
      @Override
      public void service(Mail email) throws MessagingException {
        doYourThingWith(email);
      }
    
      private void doYourThingWith(Mail email){
        // TODO something with the email
      }
    }
    
  2. Build the Mailet into a jar file

  3. Add the resulting jar file to /conf/lib folder

  4. Edit /conf/mailetcontainer.xml file where you would add this:

    <mailet match="All" class="myMailet">
        <myNeatParameter>some value</myNeatParameter>
    </mailet>
    

    as a child element to the root processor (or whatever you think is proper).

  5. Restart James

Well it's not a script, but it is very good (if not even the best) solution.


You could use Mail::POP3Client to poll the mailbox for messages. Or if the mailbox supports IMAP and you want to continuously monitor it, use an IMAP module, perhaps Net::IMAP::Simple ?

I just googled for [Asterisk Perl] and a guide called "How to Write a Perl AGI Application" appeared on the first page. It describes how to use the Asterisk::AGI module to connect to an Asterisk server using Perl.

Finally, you'll need a text-to-speech application. I'm sure there are many of these available. They probably won't be written in Perl, but there may be existing Perl interfaces for them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜