Difference between revisions of "Outgoing mail via gmail"

From Amahi Wiki
Jump to: navigation, search
Line 1: Line 1:
tags: mail gmail f14 postfix relay
 
 
 
{{MessageBox|
 
{{MessageBox|
 
backgroundcolor = #faa|
 
backgroundcolor = #faa|
Line 6: Line 4:
 
heading =WARNING|
 
heading =WARNING|
 
message = This is recommended only for advanced users, proceed with caution.}}
 
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>
+
This can be used to send mails from your Fedora 19/Amahi 7 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.<br>
 
To receive emails meant for the root user, you have to [[Forward_System_Emails|Forward System Emails]] after finishing this.<br>
I took the information from [http://carlton.oriley.net/blog/?p=31 this page] and modified them slightly for Fedora 14 / Amahi 6. <br><br>
+
 
First of all, install postfix and remove sendmail: <br>
+
* First of all, install postfix and remove sendmail: <br>
 
{{Code|yum -y install postfix
 
{{Code|yum -y install postfix
 
yum -y remove sendmail}}
 
yum -y remove sendmail}}
Openssl and openssl-perl are needed to generate certificates and create SSL connections to GMail<br>
 
Openssl should be installed already, but to be sure: <br>
 
{{Code|yum -y install openssl openssl-perl}}
 
A Certificate Authority is needed to create the necessary certificates. You can skip the next paragraph if you already have one:<br>
 
{{Code|cd /etc/pki/tls/misc
 
./CA –newca}}
 
*You will be prompted for the file name, hit enter to create a new CA.
 
* You will need to enter a passphrase next, be sure to remember it.
 
*Choose the Country Name, State or Province Name, Locality Name, Organization Name, and Organizational Unit Name to your liking. Be sure to remember the values, they will be needed in the key creation later.
 
*For the Common Name, type “CA” (without quotes).
 
*Take defaults for everything else and when prompted enter the passphrase from above.<br>
 
Now a key that is sent to Gmail to start the SSL encryption will be created: <br>
 
{{Code|cd /etc/pki/tls
 
mkdir gmail_relay
 
cd gmail_relay
 
openssl genrsa -out server.key 1024
 
openssl req -new -key server.key -out server.csr}}
 
You will be prompted for country etc. like when creating the CA. Enter the same values. <br>
 
As Common Name, now enter the name of your server, FQDN or not, your choice. <br>
 
{{Code|openssl ca -out server.pem -infiles server.csr}}
 
You will need to enter your passphrase again at this point.<br>
 
When asked if you want to sign the key, answer  yes, same when asked if to commit it.
 
  
Add the following to the bottom of the file /etc/postfix/main.cf.  
+
* 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.
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 SSL SMTP Relay
 
{{Text|Text=<nowiki>####</nowiki> Gmail SSL SMTP Relay
relayhost = [smtp.gmail.com]:587
+
<nowiki>#</nowiki>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
 +
 +
<nowiki>#</nowiki>Relay host configuration
 +
relayhost = [smtp.gmail.com]:587
 +
 +
<nowiki>#</nowiki>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}}<br />
  
<nowiki>#</nowiki>auth
+
* Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
smtp_sasl_auth_enable = yes
+
{{Text|Text=[smtp.gmail.com]:587 user@gmail.com:Password}}
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
+
<br />
 +
<b>NOTE:</b> Change ''user'' to your username and ''password'' to your gmail crredentials. <br />
  
<nowiki>#</nowiki>tls
+
* Build the password  database: <br>
smtp_use_tls = yes
+
{{Code|postmap hash:/etc/postfix/sasl_passwd}}
smtp_sasl_security_options = noanonymous
 
smtp_sasl_tls_security_options = noanonymous
 
smtp_tls_note_starttls_offer = yes
 
tls_random_source = dev:/dev/urandom
 
smtp_tls_scert_verifydepth = 5
 
smtp_tls_key_file = /etc/pki/tls/gmail_relay/server.key
 
smtp_tls_cert_file = /etc/pki/tls/gmail_relay/server.pem
 
smtpd_tls_ask_ccert = yes
 
smtpd_tls_req_ccert = no
 
smtp_tls_enforce_peername = no}}
 
Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
 
{{Text|Text=gmail-smtp.l.google.com user@gmail.com:password
 
smtp.gmail.com user@gmail.com:password}}
 
  
Obviously, you need to change ''user'' to your username and ''password'' to your gmail password. <br>
+
* Create /etc/postfix/tsl_policy file with your Gmail login credentials that looks like below:
Create the password database: <br>
+
{{Text|Text=[smtp.gmail.com]:587 encrypt}}
{{Code|postmap hash:/etc/postfix/sasl_passwd}}
+
<br />
 +
* Build the policy database: <br>
 +
{{Code|postmap /etc/postfix/tls_policy}}
  
Protect the files with your Gmail login data:
+
* Protect the files with your Gmail login data:
 
{{Code|chmod 600 /etc/postfix/sasl_passwd
 
{{Code|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.db
 
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.db}}
  
Restart Postfix:
+
* Restart Postfix:
{{Code|/etc/init.d/postfix restart}}
+
{{Code|systemctl restart postfix.service}}
  
Set Postifx to start on boot:
+
* Set Postifx to start on boot:
{{Code|chkconfig postfix on}}
+
{{Code|systemctl enable postfix.service }}
  
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}}
 
{{Code|echo test 1 2 <nowiki>|</nowiki> mail -s "Test mail" user@gmail.com}}
 +
  
 
See also:<br>
 
See also:<br>
[[Amahi_Mail_-_The_Free_Way|Amahi Mail - The Free Way]], not working on F14, yet.<br>
 
 
[[Forward_System_Emails|Forward System Emails]]<br>
 
[[Forward_System_Emails|Forward System Emails]]<br>
[[Enable_Outgoing_Emails|Enable Outgoing Emails]], not working on F14, yet.<br>
 
 
[[Monitor_System_Logs_via_E-mail|Monitor System Logs via E-mail]]<br>
 
[[Monitor_System_Logs_via_E-mail|Monitor System Logs via E-mail]]<br>

Revision as of 00:25, 21 November 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.

  • First of all, install postfix and remove sendmail:
bash code
​yum -y install postfix 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.
Text
​#### Gmail SSL 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:
Text
​[smtp.gmail.com]:587 user@gmail.com:Password​


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

  • Build the password database:
bash code
​postmap hash:/etc/postfix/sasl_passwd​


  • Create /etc/postfix/tsl_policy file with your Gmail login credentials that looks like below:
Text
​[smtp.gmail.com]:587 encrypt​


  • Build the policy database:
bash code
​postmap /etc/postfix/tls_policy​


  • Protect the files with your Gmail login data:
bash code
​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 chown postfix /etc/postfix/sasl_passwd chown postfix /etc/postfix/sasl_passwd.db chown postfix /etc/postfix/tsl_policy chown postfix /etc/postfix/tsl_policy.db​


  • Restart Postfix:
bash code
​systemctl restart postfix.service​


  • Set Postifx to start on boot:
bash code
​systemctl enable postfix.service ​


  • Now try sending a mail, it should reach your Gmail account:
bash code
​echo test 1 2 | mail -s "Test mail" user@gmail.com​


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