Difference between revisions of "Outgoing mail via gmail"

From Amahi Wiki
Jump to: navigation, search
m (adding tags)
 
(45 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=== Send mail through your HDA using your gmail account ===
+
{{MessageBox|
 +
backgroundcolor = #faa|
 +
image =Warning.png|
 +
heading =WARNING|
 +
message = This is recommended only for advanced users, proceed with caution.}}
 +
This tutorial is now available as the Amahi [https://www.amahi.org/apps/postfix-mail-relay Post Mail Relay] application.
  
tags: mail gmail f14 postfix relay
+
This can be used to send mails from your Amahi 7 or greater (Fedora 19 or greater) HDA and to receive system emails.  To receive emails meant for the root user, you have to [[Forward_System_Emails|Forward System Emails]] after finishing this tutorial.  You also might want to take a look at [[Masquerade_email_address|Masquerade email address]] as well.<br>
  
Warning: Only try this if you know what you’re doing.<br><br>
+
REF: [http://opentodo.net/2013/03/postfix-smtp-relay-to-smtp-gmail-com Postfix SMTP relay to SMTP gmail.com]
I took the information from [this page[http://carlton.oriley.net/blog/?p=31]] 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>
 +
<pre>yum -y install postfix mailx
 +
yum -y remove sendmail</pre>
  
    yum -y install postfix<br>
+
* 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.
    yum -y remove sendmail<br>
+
<pre>####Gmail SMTP Relay
Openssl and openssl-perl are needed to generate certificates and create SSL connections to GMail<br>
+
#TLS parameters
Openssl should be installed already, but to be sure: <br>
+
smtpd_use_tls=yes
    yum -y install openssl openssl-perl<br>
+
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
A Certificate Authority is needed to create the necessary certificates. You can skip the next paragraph if you already have one:<br>
+
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</pre><br />
  
    cd /etc/pki/tls/misc<br>
+
* Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
    ./CA.pl –newca<br>
+
<pre>[smtp.gmail.com]:587 user@gmail.com:Password</pre>
 +
<br />
 +
<b>NOTE:</b> Change ''user'' to your username and ''password'' to your gmail crredentials. <br />
  
*You will be prompted for the file name, hit enter to create a new CA.
+
* Build the password  database: <br>
* You will need to enter a passphrase next, be sure to remember it.
+
<pre>postmap hash:/etc/postfix/sasl_passwd</pre>
*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>
 
  
    cd /etc/pki/tls<br>
+
* Create /etc/postfix/tls_policy file that looks like below:
    mkdir gmail_relay<br>
+
<pre>[smtp.gmail.com]:587 encrypt</pre>
    cd gmail_relay<br>
+
<br />
    openssl genrsa -out server.key 1024<br>
+
* Build the policy database: <br>
    openssl req -new -key server.key -out server.csr<br>
+
<pre>postmap /etc/postfix/tls_policy</pre>
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>
 
    openssl ca -out server.pem -infiles server.csr<br>
 
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.  
+
* Protect the files with your Gmail login data:
You do not need to change anything else in it, as the last setting for any option is the one that is saved.
+
<pre>chmod 600 /etc/postfix/sasl_passwd
 +
chmod 600 /etc/postfix/sasl_passwd.db
 +
chmod 600 /etc/postfix/tls_policy
 +
chmod 600 /etc/postfix/tls_policy.db</pre><!--
 +
chown postfix /etc/postfix/sasl_passwd
 +
chown postfix /etc/postfix/sasl_passwd.db
 +
chown postfix /etc/postfix/tls_policy
 +
chown postfix /etc/postfix/tls_policy.db-->
  
  #### GMail SSL SMTP Relay
+
* Restart Postfix:
  relayhost = [smtp.gmail.com]:587
+
<pre>systemctl restart postfix.service</pre>
  
  #auth
+
* Set Postifx to start on boot:
  smtp_sasl_auth_enable=yes
+
<pre>systemctl enable postfix.service</pre>
  smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 
  
  #tls
+
* Now try sending a mail, it should reach your Gmail account:
  smtp_use_tls = yes
+
<pre>echo test 1 2 | mail -s "Test mail" user@gmail.com</pre>
  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<br>
 
  
Create /etc/postfix/sasl_passwd file with your GMail login credentials that looks like below:
 
  
  gmail-smtp.l.google.com user@gmail.com:password<br>
+
<b>NOTE:</b> Some ISPs will block emails sent using this method. Looking for a work around.
  smtp.gmail.com user@gmail.com:password<br>
 
  
Obviously, you need to change ''user'' to your username and ''password'' to your gmail password. <br>
+
== Troubleshooting ==
 +
* If you get the message " warning: SASL authentication failure: No worthy mechs found", install this package.
 +
yum install cyrus-sasl{,-plain}
  
Create the password database: <br>
+
:Restart Postfix
 +
  systemctl restart postfix
  
    postmap hash:/etc/postfix/sasl_passwd
+
* Receive the following message:
 
+
connect to smtp.gmail.com[2607:f8b0:400e:c05::6d]:587: Network is unreachable
 
+
:To correct this problem, change /etc/postfix/main.cf as follows:
    Protect the files with your GMail login data:
+
inet_protocol = ipv4
 
+
:Restart postfix
    chmod 600 /etc/postfix/sasl_passwd
+
systemctl reload postfix
    chmod 600 /etc/postfix/sasl_passwd.db
 
    chown postfix /etc/postfix/sasl_passwd
 
    chown postfix /etc/postfix/sasl_passwd.db<br>
 
 
 
Restart Postfix
 
 
 
    /etc/init.d/postfix restart
 
 
 
Now try sending a mail, it should reach your gmail account.
 
  
 
See also:<br>
 
See also:<br>
[[Amahi_Mail_-_The_Free_Way]], not working on F14, yet.<br>
+
[[Forward_System_Emails|Forward System Emails]]<br>
[[Forward_System_Emails]]<br>
+
[[Monitor_System_Logs_via_E-mail|Monitor System Logs via E-mail]]<br>
[[Enable_Outgoing_Mail]], not working on F14, yet.<br>
 
[[Monitor_System_Logs_via_E-mail]]<br>
 

Latest revision as of 15:36, 17 June 2020

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


This tutorial is now available as the Amahi Post Mail Relay application.

This can be used to send mails from your Amahi 7 or greater (Fedora 19 or greater) 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 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/tls_policy
chmod 600 /etc/postfix/tls_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


NOTE: Some ISPs will block emails sent using this method. Looking for a work around.

Troubleshooting

  • If you get the message " warning: SASL authentication failure: No worthy mechs found", install this package.
yum install cyrus-sasl{,-plain}
Restart Postfix
systemctl restart postfix
  • Receive the following message:
connect to smtp.gmail.com[2607:f8b0:400e:c05::6d]:587: Network is unreachable
To correct this problem, change /etc/postfix/main.cf as follows:
inet_protocol = ipv4
Restart postfix
systemctl reload postfix

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