http://qs1969.pair.com?node_id=976975

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

Hit there monks.I use Mail::Sendmail to send a mail. This works fine.Which module shoud I use to read my mail? Browsed CPAN for modules, but not sure which one to use. I am working with Windows 7.

Replies are listed 'Best First'.
Re: read mail
by atcroft (Abbot) on Jun 19, 2012 at 08:06 UTC

      It does help. With Net::POP3 I succeeded to read an (encrypted) message. Thanks for your advice.

      Is there any example code on how to work with Net::POP3, read the cpan documentation but i am not sure that i understand it all

Re: read mail
by marto (Cardinal) on Jun 19, 2012 at 08:27 UTC

    Depending on what you want to do (if it's more than simply reading a mail) Mail::Box may be of interest. See Mail::Box-Overview for more information.

Re: read mail
by zentara (Archbishop) on Jun 19, 2012 at 10:05 UTC

      Thank you very much. I was in search for just such an example. I will study it carefully.Thanks again.

Re: read mail
by chrestomanci (Priest) on Jun 19, 2012 at 08:35 UTC

    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.

      "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.