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 ]
      • hostname=localhost
      • UseTLS=Yes
      • 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]"
  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
      • To fix this change port 587 to -> port 465 in mailhub attribute in ssmtp.conf