Mail Mini-HOWTO

2011-07-06
by Gernot Walzl

Read e-mails:
mail

Send an e-mail:
mail recipient@somewhere.com

Fetchmail

~/.fetchmailrc

set postmaster "mylocalusername"
set bouncemail
set no spambounce
set softbounce
set properties ""
poll mymailserver.com with proto IMAP
  user 'my.mail@mymailserver.com' there with password 'mysecretpassword' is 'mylocalusername' here
  options keep fetchall ssl
  mda "/usr/bin/procmail -d %T"

fetchmail

Backup IMAP mailbox:

[...]
poll mymailserver.com with proto IMAP
  user 'my.mail@mymailserver.com' there with password 'mysecretpassword' is 'mylocalusername' here
  options keep fetchall ssl
  mda "formail -c >> /anywhere/inbox"
  folder INBOX
[...]

Sendmail

cd /usr/share/sendmail/cf/cf
cp sendmail-slackware.mc sendmail.mc

Get local hostname:
hostname -f

sendmail.mc

[...]
dnl# listen on localhost only
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')dnl
[...]
dnl# rewrite sender address
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl
FEATURE(`masquerade_envelope')dnl
GENERICS_DOMAIN(`myfullhostname.withdomain')dnl
[...]
dnl# use outgoing smtp server
define(`SMART_HOST',`[mail.gmx.net]')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl
[...]

m4 sendmail.mc > /etc/mail/sendmail.cf

Generics

/etc/mail/genericstable

mylocalusername    my.mail@gmx.net

makemap hash genericstable.db < genericstable

AuthInfo

/etc/mail/authinfo

AuthInfo:mail.gmx.net "U:my.mail@gmx.net" "P:mysecretpassword" "M:PLAIN"

makemap hash authinfo.db < authinfo

GnuPG

Encrypt and send an e-mail:
echo -e "Lorem ipsum\n\ndolor sit amet, consectetur, adipisci velit" | gpg -ea -r recipient@somewhere.com | mail -s "Subject" recipient@somewhere.com