Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Receiving Emails From Sendmail

by devslashneil (Friar)
on Jul 01, 2003 at 01:11 UTC ( [id://270378]=perlquestion: print w/replies, xml ) Need Help??

devslashneil has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am writing some custom mailing list software for my company,and i need to write a wrapper which email is passed to from sendmail.

I have added the appropriate information into /etc/mail/alias, and my program now recieves email to the STDIN when it is run.

My problem is that the email will contain different headers and sometimes HTML etc.

Is there a library / method for this specific purpose. Eg To take an email at this raw level and seperate it into "$mail->subject", "$mail->body" etc

This would be really useful for my program, i don't really want to go ahead and write something to do this using regexs when i assume someone has already tackled this problem before.

Any input would be much appreciated.
Cheers
Neil Archibald
- /dev/IT -

Replies are listed 'Best First'.
Re: Receiving Emails From Sendmail
by hacker (Priest) on Jul 01, 2003 at 02:52 UTC
    Perhaps this will give you a start:
    use strict; use Mail::Internet; my $message = new Mail::Internet ([<>]); my $from = $message->get('From'); my $subject = $message->get('Subject'); my $received = $message->get('Received'); my @body = @{$message->body()};
Re: Receiving Emails From Sendmail
by devslashneil (Friar) on Jul 01, 2003 at 03:49 UTC
    I was actually able to do it using MBoxParser
    Here is some sample code:
    #!/usr/bin/perl use strict; use Mail::MboxParser::Mail; my $msg = Mail::MboxParser::Mail->new([<STDIN>],[<STDIN>]); print $msg->from->{email} . "\n"; my $body = $msg->get_entity_body() . "\n"; print $body;
    Neil Archibald
    - /dev/IT -

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://270378]
Approved by Thelonius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found