mailx send attachment via Gmail

Gmail required SMTP authorized so we have to install one of {esmtp, ssmtp, msmtp} to setup up our client.

Choose sSMTP for emaple:

sSMTP Settings:

  • vim /etc/ssmtp/ssmtp.conf
    root=yourgmail@gmail.com //send mail by this account
    mailhub=smtp.gmail.com:465 //The place where the mail goes.
    Hostname=yourgmail@gmail.com //The full hostname
    UseTLS=YES //Use SSL/TLS to send secure messages to server.
    Authuser=yourgmail@gmail.com
    AuthPass=yourPassword
    FromLineOverride=YES //Optional, use root address in “From:” line adn never rewrite it
  • add “root:yourgmail@gmail.com:smtp/gmail.com:465 ” to /etc/ssmtp/revaliases

Make sSMTP as default mail server

mv /usr/sbin/sendmail /usr/sbin/sendmail.bac //It's a good habit to backup date before doing anything.
ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
/etc/init.d/sendmail restart

Now, you can use mailx, mailq, mail… commands send emails with your gmail.

PS, if you want to send attachment [<=10M] try mailx with ‘-a’ parameter. The following is an example:

[lemon@lab ~]$ mailx -a TAIR10_functional_descriptions.tar.gz xxxxxx@gmail.com
Subject: gene_fuctional_descriptions //this could be replaced by "-s" parameter
The attachment is the newest gene functional descriptions of Arabidopsis
EOT //Ctrl + D

Now you can check Sent Mail lable in Gmail to find the letter and the attachment.

Leave a Reply

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