如何实现侦听新邮件然后执行操作的脚本

时间:2011-04-15 14:11:41

标签: perl email james

我有一个apache James邮件服务器设置,我想创建一个脚本,它将侦听新邮件,然后与Asterisk服务器通信以调用用户电话号码并阅读邮件。我认为这是可能的,但找不到任何信息。我一直在使用perl脚本执行其他任务,所以如果我能用perl执行此操作就会很棒。

提前致谢

3 个答案:

答案 0 :(得分:1)

解决方案将设置一个cron作业来运行perl脚本,该脚本使用Mail::POP3Client之类的内容来检查新消息并使用(可能){{{{{{{ 1}}。如果CPAN模块不能满足您的需求,您可以始终让perl脚本执行Asterisk::AGI调用,以便与能够检查POP或与Asterisk接口的命令行工具进行交互。

答案 1 :(得分:1)

我想最好的方法是在java中编写一个Mailet并将其置于配置中,以使其监听根处理器中的所有邮件。

对于Apache James 3.0-beta5步骤将是这样的:

  1. 写下Mailet,即:

    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. 将Mailet构建为jar文件

  3. 将生成的jar文件添加到/ conf / lib文件夹

  4. 编辑/conf/mailetcontainer.xml文件,您可以在其中添加:

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

    作为根处理器的子元素(或者您认为合适的任何内容)。

  5. 重启James

  6. 嗯,这不是一个剧本,但它是非常好的(如果不是最好的)解决方案。

答案 2 :(得分:0)

您可以使用Mail::POP3Client轮询邮箱中的邮件。或者,如果邮箱支持IMAP并且您想要持续监控它,请使用IMAP模块,也许Net::IMAP::Simple

我只是用[Asterisk Perl]搜索,a guide called "How to Write a Perl AGI Application"出现在第一页上。它描述了如何使用Asterisk::AGI模块使用Perl连接到Asterisk服务器。

最后,您需要一个文字转语音应用程序。我相信有很多可用的。它们可能不会用Perl编写,但可能存在Perl接口。