How to use gmail smtp to send mail
Firstly you need postfix compiled with SASL and ssl support.
Enter this command into your shell.
Here is the output:
linux-gate.so.1 => (0xffffe000) libpostfix-master.so.1 => /usr/lib/libpostfix-master.so.1 (0xb7f43000) libpostfix-tls.so.1 => /usr/lib/libpostfix-tls.so.1 (0xb7f38000) libpostfix-dns.so.1 => /usr/lib/libpostfix-dns.so.1 (0xb7f33000) libpostfix-global.so.1 => /usr/lib/libpostfix-global.so.1 (0xb7f0c000) libpostfix-util.so.1 => /usr/lib/libpostfix-util.so.1 (0xb7ee6000) libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8 (0xb7ea9000) libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb7d7b000) libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0xb7d67000) libdb-4.3.so => /usr/lib/libdb-4.3.so (0xb7c8a000) libnsl.so.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7c75000) libresolv.so.2 => /lib/tls/i686/cmov/libresolv.so.2 (0xb7c62000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b33000) libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7b30000) libz.so.1 => /usr/lib/libz.so.1 (0xb7b1b000) /lib/ld-linux.so.2 (0xb7f59000)
If you dont see libssl and libsasl, this wont work, and you’ll need to recompile with support.
Generate a CSR for this server
This command, /usr/lib/ssl/misc/CA.pl -newca, will ask you to enter a name. Just hit enter to create.
$ cd /etc/postfix/certs
$ /usr/lib/ssl/misc/CA.pl -newca
$ openssl genrsa -out server.key 1024
$ openssl req -new -key server.key -out server.csr
$ openssl ca -out server.pem -infiles server.csr
If you get an error after running that last command that looks like the following,
Certificate is to be certified until Jun 15 19:38:32 2011 GMT (365 days) Sign the certificate? [y/n]:y failed to update database TXT_DB error number 2
Open /usr/lib/ssl/openssl.cnf and look for this line,
database = $dir/index.txt # database index file.
$dir is probably demoCA in the location where you ran openssl in the last command. Anyway, my file was located at demoCA/index.txt.
Open that file, and remove the line that contains your entry. I only had one entry, so I just deleted the line and saved the file.
Now go back and run the last command,
That should end with success. Fingers crossed ;)
OR
You can open demoCA/index.txt.attr and set,
unique_subject = no
And then run the last command,
Now include these /etc/postfix/main.cf modifications:
relayhost = [smtp.gmail.com]:587 #auth smtp_sasl_auth_enable=yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd #tls 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/server.key smtp_tls_cert_file=/etc/postfix/certs/server.pem smtpd_tls_ask_ccert = yes smtpd_tls_req_ccert =no smtp_tls_enforce_peername = no
Create /etc/postfix/sasl_passwd file
This is the format of the sasl_passwd file.
Copy this text and edit with your account details then highlight and copy.
gmail-smtp.l.google.com user@gmail.com:password smtp.gmail.com user@gmail.com:password
Enter these commands line by line and press enter after each line.
(Below are the 4 commands to run inside of vim.)
a
ctr + shift + v
esc
!wq
$ postmap /etc/postfix/sasl_passwd
$ /etc/init.d/postfix reload
References
- http://bookmarks.honewatson.com/2008/04/20/postfix-gmail-smtp-relay/ »
- http://www.marksanborn.net/linux/send-mail-postfix-through-gmails-smtp-on-a-ubuntu-lts-server/ »
[Click to add or edit comments])
Please prepend comments below including a date