Tech News

Reading Mail with POP3-Perl,RSS Feed of Your Inbox , 2nd Edition and Cookbook

Accessing All the Data of a Message

Mail: Webmail::Gmail can, of course, give you all of the information within a message. However, relying on addressing the data directly within your script is a recipe for trouble. Even as I type this sentence, the Gmail UI seems to be changing and rendering bits of Mail: Webmail::Gmail out of date until either Gmail changes back or the library is fixed. Do something like this to make sure that such changes don’t entirely break your code.

As you can see from the in-code comments, this code can’t deal with attachments. So it’s time you learned how.

Listing the Mail and Displaying a Chosen Message

So, with that all fully understood, you can put your knowledge and use it. Code that logs in displays the mail you have in your account in a list and then lets you select the one you want to read. Select that, and it displays it. Easy and useful. It uses the Utils. Pm module to deal with the login procedure. As you can see from the in-code comments, this code can’t deal with attachments. It’s time you learned how.

Dealing with Attachments

Gmail’s enormous storage capacity allows you to use it for huge attachments. There are many possibilities for this feature, but first, you need to know how to retrieve the branches themselves. You retrieve an extension in a way very closely connected to the method you used in the RSS script. First, recover the list of messages and then loop through them, pulling out the data on each note. Here you differ — you’re looking for an attachment, so you test to see if one is present and if so, you go on to do something about it.

Making an RSS Feed of Your Inbox

So now you know how to gather the mail from a specific folder and print it out. Let’s do something more useful with it, as an exercise. How about an RSS feed of your Inbox? You already made a feed that displays the unread message count. Do the same here, only showing the messages instead, followed by a walkthrough.


To install and run this script, place it in a CGI-enabled directory on your server, and remember to CHMOD it to executable. This script highlights a simple method of gathering messages and doing something with them. As you saw in the previous chapter, you can easily direct the get messages () function, which above retrieves the array of hashes from the Inbox.

In this chapter, then, you’ve learned how to retrieve e-mails from Gmail using Perl. You should now be able to access the data of any mail you wish and use it within your programs. As you will see in the later chapters, this opens many new opportunities. In the next chapter, you learn how to send mail via Gmail.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button