http://www.perlmonks.org?node_id=976983


in reply to read mail

Reading mail is not as easy as sending it. To send mail perl only have to speak smtp which is a fairly simple protocol, so there are many tools for the purpose. Also as email is sent via store an forward, you only need to generate the message and send it on it's first hop, and the onward servers take care of the rest.

For receiving email it is more tricky because of the store and forward nature of the protocol. As atcroft said, if your mail is being delivered and stored to a POP3, or IMAP mailbox, then there are perl modules on cpan that will retrieve mail from those mailboxes.

It is also possible that your mail will be on some sort of webmail system like google mail. If that is the case then you will have to write or find code to scrape the website using modules such as HTML::TreeBuilder or WWW::Mechanize::Firefox, though in the case of Google, you can configure your account to be accessible via IMAP.

Finally it might be possible to receive mail directly over SMTP rather than polling a mailbox using something like Net::SMTP::Server or NetServer::SMTP. This would have the advantage of allowing your script to respond to incoming mails in realtime, but to do that you would need your own domain name where you can control the MX record in the DNS, your script would receive all mail to that domain you would need to manually forward any destined for other users yourself. Also you would need to be very cautions setting up such a server on an internet facing site due to the risk of remote hack attacks.

Replies are listed 'Best First'.
Re^2: read mail
by marto (Cardinal) on Jun 19, 2012 at 08:55 UTC

    "It is also possible that your mail will be on some sort of webmail system like google mail. If that is the case then you will have to write or find code to scrape the website using modules such as HTML::TreeBuilder or WWW::Mechanize::Firefox, though in the case of Google, you can configure your account to be accessible via IMAP."

    Webmail systems such as Gmail prohibit scraping/automating their web interfaces in their terms of use. For access they allow POP3 and SMTP. http://support.google.com/mail/bin/answer.py?hl=en&answer=13287.