Difference between revisions of "Outgoing mail via gmail"

From Amahi Wiki
Jump to: navigation, search
Line 9: Line 9:
  
 
* First of all, install postfix and remove sendmail: <br>
 
* First of all, install postfix and remove sendmail: <br>
{{Code|yum -y install postfix mailx
+
<pre>yum -y install postfix mailx
yum -y remove sendmail}}
+
yum -y remove sendmail</pre>
  
 
* Add the following to the bottom of the file /etc/postfix/main.cf. You do not need to change anything else in it, as the last setting for any option is the one that is saved.
 
* Add the following to the bottom of the file /etc/postfix/main.cf. You do not need to change anything else in it, as the last setting for any option is the one that is saved.
{{Text|Text=<nowiki>####</nowiki>Gmail SMTP Relay
+
<pre>####Gmail SMTP Relay
<nowiki>#</nowiki>TLS parameters
+
#TLS parameters
 
smtpd_use_tls=yes
 
smtpd_use_tls=yes
 
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
 
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
Line 21: Line 21:
 
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
 
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
 
   
 
   
<nowiki>#</nowiki>Relay host configuration
+
#Relay host configuration
 
relayhost = [smtp.gmail.com]:587
 
relayhost = [smtp.gmail.com]:587
 
   
 
   
<nowiki>#</nowiki>SASL Configuration
+
#SASL Configuration
 
smtp_sasl_auth_enable = yes
 
smtp_sasl_auth_enable = yes
 
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 
smtp_sasl_security_options = noanonymous
 
smtp_sasl_security_options = noanonymous
 
smtp_sasl_mechanism_filter = plain
 
smtp_sasl_mechanism_filter = plain
smtp_sasl_tls_security_options = noanonymous}}<br />
+
smtp_sasl_tls_security_options = noanonymous</pre><br />
  
 
* Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
 
* Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
{{Text|Text=[smtp.gmail.com]:587 user@gmail.com:Password}}
+
<pre>[smtp.gmail.com]:587 user@gmail.com:Password</pre>
 
<br />
 
<br />
 
<b>NOTE:</b> Change ''user'' to your username and ''password'' to your gmail crredentials. <br />
 
<b>NOTE:</b> Change ''user'' to your username and ''password'' to your gmail crredentials. <br />
  
 
* Build the password  database: <br>
 
* Build the password  database: <br>
{{Code|postmap hash:/etc/postfix/sasl_passwd}}
+
<pre>postmap hash:/etc/postfix/sasl_passwd</pre>
  
 
* Create /etc/postfix/tls_policy file with your Gmail login credentials that looks like below:
 
* Create /etc/postfix/tls_policy file with your Gmail login credentials that looks like below:
{{Text|Text=[smtp.gmail.com]:587 encrypt}}
+
<pre>[smtp.gmail.com]:587 encrypt</pre>
 
<br />
 
<br />
 
* Build the policy database: <br>
 
* Build the policy database: <br>
{{Code|postmap /etc/postfix/tls_policy}}
+
<pre>postmap /etc/postfix/tls_policy</pre>
  
 
* Protect the files with your Gmail login data:
 
* Protect the files with your Gmail login data:
{{Code|chmod 600 /etc/postfix/sasl_passwd
+
<pre>chmod 600 /etc/postfix/sasl_passwd
 
chmod 600 /etc/postfix/sasl_passwd.db
 
chmod 600 /etc/postfix/sasl_passwd.db
 
chmod 600 /etc/postfix/tsl_policy
 
chmod 600 /etc/postfix/tsl_policy
chmod 600 /etc/postfix/tsl_policy.db<!--
+
chmod 600 /etc/postfix/tsl_policy.db</pre><!--
 
chown postfix /etc/postfix/sasl_passwd
 
chown postfix /etc/postfix/sasl_passwd
 
chown postfix /etc/postfix/sasl_passwd.db
 
chown postfix /etc/postfix/sasl_passwd.db
 
chown postfix /etc/postfix/tsl_policy
 
chown postfix /etc/postfix/tsl_policy
chown postfix /etc/postfix/tsl_policy.db-->}}
+
chown postfix /etc/postfix/tsl_policy.db-->
  
 
* Restart Postfix:
 
* Restart Postfix:
{{Code|systemctl restart postfix.service}}
+
<pre>systemctl restart postfix.service</pre>
  
 
* Set Postifx to start on boot:
 
* Set Postifx to start on boot:
{{Code|systemctl enable postfix.service }}
+
<pre>systemctl enable postfix.service</pre>
  
 
* Now try sending a mail, it should reach your Gmail account:
 
* Now try sending a mail, it should reach your Gmail account:
{{Code|echo test 1 2 <nowiki>|</nowiki> mail -s "Test mail" user@gmail.com}}
+
<pre>echo test 1 2 | mail -s "Test mail" user@gmail.com</pre>
  
  

Revision as of 00:38, 2 December 2013

Warning.png WARNING
This is recommended only for advanced users, proceed with caution.


This can be used to send mails from your Fedora 19/Amahi 7 HDA and to receive system emails. To receive emails meant for the root user, you have to Forward System Emails after finishing this tutorial. You also might want to take a look at Masquerade email address as well.

REF: Postfix SMTP relay to SMTP gmail.com

  • First of all, install postfix and remove sendmail:
yum -y install postfix mailx
yum -y remove sendmail
  • Add the following to the bottom of the file /etc/postfix/main.cf. You do not need to change anything else in it, as the last setting for any option is the one that is saved.
####Gmail SMTP Relay
#TLS parameters
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_note_starttls_offer = yes
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
 
#Relay host configuration
relayhost = [smtp.gmail.com]:587
 
#SASL Configuration
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_sasl_tls_security_options = noanonymous


  • Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
[smtp.gmail.com]:587 user@gmail.com:Password


NOTE: Change user to your username and password to your gmail crredentials.

  • Build the password database:
postmap hash:/etc/postfix/sasl_passwd
  • Create /etc/postfix/tls_policy file with your Gmail login credentials that looks like below:
[smtp.gmail.com]:587 encrypt


  • Build the policy database:
postmap /etc/postfix/tls_policy
  • Protect the files with your Gmail login data:
chmod 600 /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd.db
chmod 600 /etc/postfix/tsl_policy
chmod 600 /etc/postfix/tsl_policy.db
  • Restart Postfix:
systemctl restart postfix.service
  • Set Postifx to start on boot:
systemctl enable postfix.service
  • Now try sending a mail, it should reach your Gmail account:
echo test 1 2 | mail -s "Test mail" user@gmail.com


See also:
Forward System Emails
Monitor System Logs via E-mail