3

I would like to use the mail command in a shell script to automatically connect to my Gmail/Yahoo/Hotmail account and send/receive messages. How can I do this?

fouric
  • 2,281
  • 2
    mail(x) doesn't speak any network protocols (IMAP, POP, SMTP). You would need to configure your local MTA (that provides /usr/lib/sendmail) to login to your remote account and use it as a smarthost. For receiving, you would need something external such as fetchmail. Use a better MUA. – jordanm May 20 '13 at 21:33

3 Answers3

2

Also I'd take a look at fetchmail. Fetchmail can be used to download mail from POP3/IMAP servers and deliver it locally. There's a good tutorial here to get you started, titled: Using Fetchmail to Retrieve Email.

Examples

If you create a .fetchmailrc file in your $HOME directory as follows:

poll mail.example.com protocol imap:
     username "admin" password "dir3cti0n" is "squire" here;
     username "fore" password "0rd3r" is "foreman" here;

poll mail.example.org protocol pop3:
     user "betty" password "p1nk" mda "/usr/bin/procmail -d %T"

The first rule will poll mail.example.com for mail using IMAP for the users admin & fore and deliver any mail for admin to squire (local user) and foreman (local user).

The second rule will use pop3 and any mail for betty will be run through procmail for delivery.

References

slm
  • 369,824
0

You can't. Anything "mail" doesn't speak imap, which most of the web-based services offer as an alternative.

Consider installing/using mutt.

tink
  • 6,765
0

How about Mutt email client?

Here is a link for tutorial:

http://crunchbanglinux.org/wiki/howto/howto_setup_mutt_with_gmail_imap

Raza
  • 4,109
  • Thanks for the link, but please refrain from link-only answers. If you have a link but not much else to say, then please create a comment. – fouric May 20 '13 at 23:41