NOTE: For complete and latest version please refer to http://wiki.debian.org/GmailAndExim4
Background
My email server seems a bit crazy on these day: both GMail and Yahoo! Mail block a direct send from my server because of following reason:
hswong3i@gmail.com
SMTP error from remote mail server after end of data:
host gmail-smtp-in.l.google.com [209.85.143.114]:
550-5.7.1 [x.x.x.x] The IP you're using to send mail is not authorized to
550-5.7.1 send email directly to our servers. Please use the SMTP relay at your
550-5.7.1 service provider instead. Learn more at http://mail.google
550 5.7.1 .com/support/bin/answer.py?answer=10336 d4si2957764tib.28
When checking http://mail.google.com/support/bin/answer.py?answer=10336 it give me the following reason:
In order to prevent spam, Gmail refuses mail when the sending IP address does not match the sending domain. To send mail from your server to Gmail, we suggest using the SMTP relay provided by your ISP. Please note that we are unable to whitelist IP addresses or otherwise make exceptions at this time.
First of all I guess this is due to the use of dynamic IP, with only forward DNS record (A/MX/CNAME) but no reserve record (PTR). But even update my own DNS server with reserve record, no one else are able to discover it though internet. So I have no way to prove my IP is under my control, and so can't prove myself as not spammer.
Secondly, I try to use SMTP relay from my own ISP. BTW, as I am using HGC broadband my username and password is required for the connection. Ok, this is another issue and not my cup of tea :S
Finally, I try to configure my Exim4 to send email though my own Gmail account. This should be most simple because it will no longer depend on my internet connection, and so I can change my ISP whenever and whatever. Here are some procedure for Debian Lenny.
Procedure for Debian Lenny
Run dpkg-reconfigure exim4-config with following options:
- General type of mail configuration: mail sent by smarthost; received via SMTP or fetchmail
- System mail name: Your SMTP FNDQ, e.g. smtp.example.com
- IP-addresses to listen on for incoming SMTP connections: left as empty
- Other destinations for which mail is accepted: Some FNDQ of your domain, e.g. example.com, *.example.com
- Domains to relay mail for: Other server of your domain, e.g. *.example.com
- Machines to relay mail for: Your local subnet, e.g. 192.168.0.0/24
- IP address or host name of the outgoing smarthost: smtp.gmail.com::587
- Hide local mail name in outgoing mail? No
- Keep number of DNS-queries minimal (Dial-on-Demand)? No
- Delivery method for local mail: Maildir format in home directory
- Split configuration into small files? Yes
Next, edit /etc/exim4/passwd.client and add the following lines (Note: change information accordingly):
gmail-smtp.l.google.com:yourAccountName@gmail.com:y0uRpaSsw0RD
*.google.com:yourAccountName@gmail.com:y0uRpaSsw0RD
smtp.gmail.com:yourAccountName@gmail.com:y0uRpaSsw0RD
Finally, run update-exim4.conf and everything should work fine (You may also run dpkg-reconfigure exim4-config again and double check every setup). Try to send an email to somewhere else and check your log from /var/log/exim/mainlog.
Restriction
Well... GMail SMTP server will rewrite my mail sender (e.g. someone@example.com) into my GMail account (e.g. someotherelse@gmail.com)... This is not what I am really asking for... Well... So I will fallback to use ISP SMTP relay solution... Most likely they are working in same idea :D
Some other tips
Remember that Gmail is using port 587 + TLS for SMTP relay. Always remember to check if TLS support enabled if you face any error.