Posts tagged ‘gmail’

Send mail from the command line on Mac OSX

I’ll be using my Gmail account to send mail. The first step is to configure the local Postfix server as a relay. Edit /etc/postfix/main.cf:

sudo vim /etc/postfix/main.cf

Search for a “relayhost=” line and add the following after it:

relayhost = smtp.gmail.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_sasl_local_domain = yourdomain.com
#smtpd_sasl_application_name = smtpd
broken_sasl_auth_clients = yes
smtpd_pw_server_security_options = noanonymous
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom

Next create /etc/postfix/sasl_passwd and add the following (replace username and password accordingly):

smtp.gmail.com:587 username@gmail.com:password

Next run the following commands:

$ sudo postmap hash:/etc/postfix/sasl_passwd
$ sudo chown root:wheel /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
$ sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

You should be able to send mail from the command line now:

$ mail -s "Test" username@domain.com

You can check mail’s log file at /var/log/mail.log

To be able to send attachments from the command line (true attachments that graphical mail clients understand) install mutt:

$ curl -O ftp://ftp.mutt.org/mutt/devel/mutt-1.5.20.tar.gz
$ tar xfzvv mutt-1.5.20.tar.gz 
$ cd mutt-1.5.20/
$ ./configure
$ make
$ sudo make install

To send attachments use the following command:

echo "text body" | mutt -s "subject" -a file.dat -- username@domain.com

Or even better:

for i in {1..1000}; do echo "text body" | mutt -s "subject" -a file.dat -- username@domain.com; done

Happy mailing!