The question is too broad to give any particular advice, but here's a broad overview.
The simple, naive approach is to use "screen scraping". Create a script which uses a text-mode browser such as lynx or w3m and logs in and downloads the web page. Post-process the web page to a suitable format. There are
Perl and PHP modules for making this almost palatable. There used to be a script called "gotmail" which downloaded mail from Hotmail using this approach.
If the webmail service offers POP or IMAP access, that is probably preferrable. Again, there are
Perl and PHP and Python modules if you want to write your own simple client. Or have a look at fetchmail if all you need is the ability to download mail.
Web 2.0 webmail providers might offer their own simple Ajax API for manipulating their service. I haven't seen any but that would be a very zeitgeist thing to do for them. (I don't use Gmail but imagine they might have something like this. But then they have IMAP which in many ways might be preferable unless you specifically want to play with their calendar integration or something.)