Monday, March 30, 2015

Send email with linux

This is very use full for raspberry pi projects.Email temperature information, notify things when you not there.And the best thing is its really easy to configure.I'll go through step by step.

  1. First thing is to install ssmtp.
    • sudo apt-get install ssmtp
  2. Edit and add new configurations to ssmtp.conf file. 
    • nano /etc/ssmtp/ssmtp.conf [add new line or change current lines ]
      • root=your.email@gmail.com
      • mailhub=smtp.gmail.com:587
      • rewriteDomain=gmail.com
      • hostname=localhost
      • UseTLS=Yes
      • AuthUser=your.email
      • AuthPass=your.password
      • UseSTARTTLS=Yes
      • FromLineOverride=YES
    • ctrl+O [nano save]
    • ctrl+X [nano exit]
  3. Install mailutils to send emails from terminal.
    • sudo apt-get install mailutils
    • Sending a test mail
      • echo "Email Body [Happy Coding]" | mail -s "Email Subject [Finally Done]" your.email@gmail.com
  4. Possible errors and how to fix them.
    • mail: cannot send message: Process exited with a non-zero status
      • check the error log >> cat /var/log/mail.err or cat /var/log/mail.log
      • If its Authorization failed (xxxxxxxxxxxxxxxxxxxxxxxxxx)
    • sSMTP[1564]: Cannot open smtp.gmail.com:587
      • To fix this change port 587 to -> port 465 in mailhub attribute in ssmtp.conf 
        • mailhub=smtp.gmail.com:465