Configuring Gmail as SMTP Relay on Elastix
Elastix uses Postfix, and getting Postfix configured to use Gmail as a SMTP Relay has been incredibly painful to do. This should not be as difficult as it turned out to be, but here is what I had to do to get things working.
Edit the /etc/postfix/main.cf file
nano /etc/postfix/main.cf
Change these lines to your external domain and the name of your elastix server:
################################ #Ingresado por yb-webadmin mydomain = myrealdomain.gotdns.org myhostname = elastix.myrealdomain.gotdns.org
Change the following line
#relayhost = [an.ip.add.ress]to
relayhost = [smtp.gmail.com]:587
Create a new file /etc/postfix/sasl_passwd and put the following line in it
[smtp.gmail.com]:587 loginname@gmail.com:password
Then run the following command
postmap hash:/etc/postfix/sasl_passwd
Create a directory /etc/postfix/certs. Generate a self-signed certificate as follows
cd /etc/postfix/certs openssl req -new -x509 -keyout cakey.pem -out cacert.pem -days 365 openssl genrsa -out gm.key 1024 openssl req -new -key gm.key -out gm.csr openssl ca -cert cacert.pem -keyfile cakey.pem -out ./gm.pem -infiles gm.csr
If you get an error that says something like
Could not open directory ../../CA/newcerts
then do the following before you run the commands above
mkdir -p ../../CA/newcerts touch ../../CA/index.txt echo "01" >> ../../CA/serial
and after you are done, you can remove the above directory using
rm -rf ../../CA
Add the following lines to /etc/postfix/main.cf
smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = smtp_use_tls = yes 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/postfix/certs/gm.key smtp_tls_cert_file=/etc/postfix/certs/gm.pem smtpd_tls_ask_ccert = yes smtpd_tls_req_ccert =no smtp_tls_enforce_peername = no
And finally run
postfix reload
Check your setup by sending a test email
mail myself@myemail.comAnd check the logs for anything going wrong
tail -f /var/log/maillog
Victor Casale
Can you please help me?
When i type
echo “01″ >> ../../CA/serial
I get the following message:
bash: syntax error near unexpected token `&’
I’m i doing something wrong?
Thank you
Jun 20, 2009 @ 7:06 pm
Chris
I just wanted to sincerely thank you for publishing your findings — I feel confident that, without your help, I would not have figured this out on my own!
Just wanted to let you know that I got this to work with one modification:
Instead of using this command:
echo “01″ >> ../../CA/serial
I used:
echo “01″ > ../../CA/serial
And now everything is working.
Quick question. Do you know how in postfix to specify the name of the relay sender. Right now it is coming from root and I’d like it to come from a different name than root.
Thanks, once again, for publishing your hard work!
Chris
Jun 23, 2009 @ 5:35 pm