Changes

From Amahi Wiki
Jump to: navigation, search
tags: mail gmail ubuntu postfix relayexim4
{{MessageBox|
message = This is recommended only for advanced users, proceed with caution.}}
This can be used to send mails from your HDA and to receive system emails.<br>
To receive emails meant for the root user, you have to [[Forward_System_Emails|Forward System Emails]] after finishing this tutorial. Recommend you do not use copy and paste as there are hidden special characters that sometimes cause issues.<br>
Install postfix '''NOTE:''' Recommend you do not use copy and remove sendmail: paste as there are hidden special characters that sometimes cause issues.<br>{{Code|sudo apt-get -y install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules}}
== Option 1 (Postfix) == sudo apt-get -y install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules ::'''NOTE:''' During install of postfix, a popup box may display. If it does, select '''OK''' and then '''''Internet'''''. Add your domain name (i.e. home.com) and then select '''OK'''.
Add the following to the bottom of '''/etc/postfix/main.cf''':
{{Text|relayhost<nowikipre> relayhost = </nowiki>[smtp.gmail.com]:587smtp_sasl_auth_enable<nowiki> = </nowiki>yessmtp_sasl_password_maps<nowiki> = </nowiki>hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options<nowiki> = </nowiki>noanonymoussmtp_tls_CAfile<nowiki> = </nowiki>/etc/postfix/cacert.pemsmtp_use_tls<nowiki> = yes</nowikipre>yes}}
Create '''/etc/postfix/sasl_passwd''' file with your Gmail login credentials as shown below(change ''user'' and ''password'' to your Gmail user name and password.):{{Text|Text= [smtp.gmail.com]:587 user@gmail.com:password}} Obviously, you need to change ''user'' to your username and ''password'' to your gmail password. <br>
Create the password database: <br>
{{Code| sudo postmap hash:/etc/postfix/sasl_passwd}}
Protect the files with your Gmail login data:
{{Code| sudo chown root:root /etc/postfix/sasl_passwd sudo chmod 600 /etc/postfix/sasl_passwd}}
Validating the certificate:
{{Code| cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem <nowiki>|</nowiki> sudo tee -a /etc/postfix/cacert.pem}}
Restart Postfix:
{{Code| sudo /etc/init.d/postfix restart}} == Option 2 (Exim4) == sudo apt-get install exim4 mailx Ensure you verify the hostname before proceeding. You will need this later. hostname After installing exim4 we need to configure it. This is done by the following command: sudo dpkg-reconfigure exim4-config Now you need to answer some questions. Don't worry I'll give you the answers to those questions.* General type of mail configuration: <code>mail sent by smarthost; received via SMTP or fetchmail</code>* The next question asks for the system mail name: <code>Set to same as hostname</code>* Now it asks you what IP addresses should be allowed to use the server. <code>Leave as is (127.0.0.1 ; ::1)</code>* Other destinations for which mail is accepted: <code>Set to same as hostname</code>* Machines to relay mail for: <code>Leave blank</code>* IP address or host name of outgoing smarthost: <code>smtp.gmail.com::587</code>* Hide local mail name in outgoing mail: <code>No</code>* Keep number of DNS-queries minimal: <code>No</code>* Delivery method for local mail: <code>mbox format in /var/mail/</code>* Split configuration into small files: <code>No</code><br />After answering all these questions exim4 will restart and we're halfway home. Now you'll have to enter your account details. As root, edit the file /etc/exim4/passwd.client and add the next three lines at the end of the file.<pre>gmail-smtp.l.google.com:YOU@gmail.com:PASSWORD*.google.com:YOU@gmail.com:PASSWORDsmtp.gmail.com:YOU@gmail.com:PASSWORD</pre> ::'''NOTE:''' You'll have to change ''YOU'' to your Gmail login name, and ''PASSWORD'' to your password on all three lines.  This password file contains sensitive account information. You should verify its file permissions and ownership.:<code>$ ls -al /etc/exim4/passwd.client</code>:<code>-rw-r----- 1 root Debian-exim 252 Mar 25 17:24 /etc/exim4/passwd.client</code> If they are different from the above, use the following commands to set file permissions and ownership. sudo chown root:Debian-exim /etc/exim4/passwd.client sudo chmod 640 /etc/exim4/passwd.client After that you only have to update and restart exim and you're done! The next two lines will do that for you: sudo update-exim4.conf sudo /etc/init.d/exim4 restart exim4 -qff ::'''NOTE:''' The <code>-qff</code> parameter forces a delivery attempt for every message, whether frozen or not.
== Test Email ==
Now try sending a mail, it should reach your Gmail account (change user to match your account name):
{{Code| echo "This is Content" <nowiki>|</nowiki> sudo mail -s "This is subject" user@gmail.com}}
Check the mail log:
{{Code| tail -f /var/log/mail.log}}
If all goes well, you should not see any errors. When you check your account, it is possible the email will appear as SPAM. Be sure to check that folder for it.
Reference: <br />* [http://yaui.me/postfix-gmail-smtp-server-relay-ubuntu Postfix + Gmail SMTP server relay in Ubuntu]<br />* [http://linuxcommando.blogspot.com/2014/04/how-to-setup-exim4-on-debian-to-use.html How to setup exim4 on Debian to use Gmail]<br />* [http://www.sbprojects.com/projects/raspberrypi/exim4.php Prepare Your Pi To Send Mail Through Gmail]
12,424

edits