Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Mail Processing

by virtualweb (Sexton)
on May 29, 2011 at 14:06 UTC ( #907208=perlquestion: print w/replies, xml ) Need Help??
virtualweb has asked for the wisdom of the Perl Monks concerning the following question:


I have asked my server to redirect all email which come to a particular email box to a little perl script so I can automate sending an auto-reply according to keywords in the Subject or Body.

Now I need to write the script but I have no knowledge of how to parse the email To: From: Subject: and Body:

I looked in for clues and found two results:

1) a Module called Mail::Message

2) a directory of mail related modules

If anyone has already parsed email messages I would appreciate directions, perhaps your've already used the above mentioned Modules or you may have a better a quicker solution.

Much appreciated

Replies are listed 'Best First'.
Re: Mail Processing
by ig (Vicar) on May 29, 2011 at 19:28 UTC

    I have used MIME::Parser and would use it again. Many messages are multi-part MIME and the MIME::Tools set of modules makes it easy to compose them and extract their parts. The documentation might seem a bit overwhelming in the beginning, but what you need for basic parsing is usually quite simple.

Re: Mail Processing
by gnosti (Hermit) on May 29, 2011 at 21:34 UTC
    Modules in the Mail::* hierarchy are known for being featureful and heavyweight. Email::Filter is part of the Email::* family of lighter, simpler modules launched by Simon Cozens and others. I use it for filtering mail I download with Net::IMAP::Client
Re: Mail Processing
by SimonClinch (Deacon) on May 29, 2011 at 15:53 UTC
    Owing to the variations that can still exist in the format, please provide some example mails to parse. Be aware that you might also get multiple formats, attachments etc.

    One world, one people

Re: Mail Processing
by bliffle (Initiate) on May 30, 2011 at 18:44 UTC
    I would suggest using procmail instead of attempting to re-invent that wheel:
      FWIW, Mail::Audit, and its successor Email::Filter, were actually developed in reaction to procmail's unusual syntax. Being able to put perl code in my filtering rules is a winner for me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://907208]
Approved by Corion
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-06-19 06:06 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.