Difference between revisions of "Use gmail as smtp server"

From BubbaWiki
Jump to navigation Jump to search
(Created page with ' Contributed by Albert Pauw (Work in progress) cd /etc/postfix cp main.cf main.cf.org (just to be sure, we save a copy). Now we edit the file main.cf: The following lines nee...')
 
m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Contributed by Albert Pauw ('''Work in progress)'''


Contributed by Albert Pauw (Work in progress)
[http://wiki.excito.org/wiki/index.php/User:TheWebalyst TheWebalyst]: I got this working by changing the sasl_passwd setting (working version below). It is not clear if Albert's "Work in progress" was working or not, but the sasl_passwd setting did not work for me, and appeared to be incorrect so following these corrected instructions should now work.


cd /etc/postfix
Just to be sure, we save a copy:
cp main.cf main.cf.org


(just to be sure, we save a copy).
cd /etc/postfix cp main.cf main.cf.org


Now we edit the file main.cf:
Now we edit the file main.cf:  


The following lines need to be changed:
The following lines need to be changed:  


mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
change to -> mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
192.168.1.0/24


Obviously you add your internal network, 192.168.1.0 is a good guess
change to
(192.168.0.0 is another much used one). If you don't do this, then your
bubba won't accept mail for relaying.


relayhost =
'''mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.0/24'''
change to -> relayhost = [smtp.gmail.com]:587


Add the following lines:
Obviously you add your internal network, 192.168.1.0 is a good guess (192.168.0.0 is another much used one).


smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
(TheWebalyst: Alternatively, if you want to send from all machines on your network and can't get the above working, comment out the mynetworks value with a '#' and insert "mynetworks_style = subnet" instead.) 
smtp_use_tls=yes
smtpd_sasl_local_domain = $myhostname
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd


Now create or edit the file sasl_passwd and add the following line with
If you don't do this, then your bubba won't accept mail for relaying.
your gmail account data:


[smtp.gmail.com]:587 <Your Gmail address>:<Your Gmail password>
relayhost =


save it and run
change to


postmap sasl_passwd
'''relayhost = [smtp.gmail.com]:587'''


To (re)generate the sasl_passwd.db file
Add the following lines:


Now restart postfix
'''smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt'''
'''smtp_use_tls=yes'''
'''smtpd_sasl_local_domain = $myhostname'''
'''smtp_sasl_tls_security_options = noanonymous'''
'''smtpd_sasl_application_name = smtpd'''


/etc/init.d/postfix restart
Now create or edit the file sasl_passwd and add the following line with your gmail account data:


Look at /var/log/mail.log
smtp.gmail.com  Your_Gmail_address:Your_Gmail_password


tail -f /var/log/mail.log
save it and run


and send an email using your bubba (b3) as smtp server.
postmap sasl_passwd
 
to (re)generate the sasl_passwd.db file.
 
Now restart postfix
 
/etc/init.d/postfix restart
 
Look at /var/log/mail.log
 
tail -f /var/log/mail.log
 
and send an email using your bubba (b3) as smtp server.  
 
== Redirecting Email for Bubba and Users  ==
 
Now your bubba can send mail to the world via gmail (as well as acting as an SMTP relay for your network) you might want mail sent to b3 users to end up elsewhere.
 
I found two postfix settings useful for this, although I ([http://wiki.excito.org/wiki/index.php/User:TheWebalyst TheWebalyst]) admit some ignorance about the ways you can do this.
 
=== Always BCC  ===
 
You can use "always_bcc" to have certain emails copied to a given email address.&nbsp;I have to admit I'm not sure of the scope of this but found that it revealed messages being sent that I didn't know about (e.g. from horde3 and DenyHosts).
<pre>always_bcc = email_address</pre>
=== Redirecting User Email  ===
 
Perhaps more useful, you can avoid having to read mail on b3 by redirecting mails for individual accounts. This Involves the follosteps:
 
1) Create a relocation map file: /etc/postfix/relocation which contains one line for each redirected user account as follows:
<pre>username  email_address</pre>
2) Edit /etc/postfix/main.cf and add the following entry:
<pre>relocated_maps = hash:/etc/postfix/relocated</pre>
3) Generate the map (failure to do this can stop postfix working!) as follows:
<pre>postmap /etc/postfix/relocated</pre>
4) Restart postfix:
<pre>/etc/init.d/postfix restart</pre>
Note: if you edit /etc/postfix/relocated you need to rebuild the map database with "postmap /etc/postfix/relocated".
 
<br>
 
<br>

Latest revision as of 13:18, 26 April 2011

Contributed by Albert Pauw (Work in progress)

TheWebalyst: I got this working by changing the sasl_passwd setting (working version below). It is not clear if Albert's "Work in progress" was working or not, but the sasl_passwd setting did not work for me, and appeared to be incorrect so following these corrected instructions should now work.

Just to be sure, we save a copy:

cd /etc/postfix cp main.cf main.cf.org

Now we edit the file main.cf:

The following lines need to be changed:

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

change to

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.0/24

Obviously you add your internal network, 192.168.1.0 is a good guess (192.168.0.0 is another much used one).

(TheWebalyst: Alternatively, if you want to send from all machines on your network and can't get the above working, comment out the mynetworks value with a '#' and insert "mynetworks_style = subnet" instead.) 

If you don't do this, then your bubba won't accept mail for relaying.

relayhost =

change to

relayhost = [smtp.gmail.com]:587 

Add the following lines:

smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
smtp_use_tls=yes
smtpd_sasl_local_domain = $myhostname
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_application_name = smtpd

Now create or edit the file sasl_passwd and add the following line with your gmail account data:

smtp.gmail.com   Your_Gmail_address:Your_Gmail_password 

save it and run

postmap sasl_passwd 

to (re)generate the sasl_passwd.db file.

Now restart postfix

/etc/init.d/postfix restart 

Look at /var/log/mail.log

tail -f /var/log/mail.log 

and send an email using your bubba (b3) as smtp server.

Redirecting Email for Bubba and Users

Now your bubba can send mail to the world via gmail (as well as acting as an SMTP relay for your network) you might want mail sent to b3 users to end up elsewhere.

I found two postfix settings useful for this, although I (TheWebalyst) admit some ignorance about the ways you can do this.

Always BCC

You can use "always_bcc" to have certain emails copied to a given email address. I have to admit I'm not sure of the scope of this but found that it revealed messages being sent that I didn't know about (e.g. from horde3 and DenyHosts).

always_bcc = email_address

Redirecting User Email

Perhaps more useful, you can avoid having to read mail on b3 by redirecting mails for individual accounts. This Involves the follosteps:

1) Create a relocation map file: /etc/postfix/relocation which contains one line for each redirected user account as follows:

username   email_address

2) Edit /etc/postfix/main.cf and add the following entry:

relocated_maps = hash:/etc/postfix/relocated

3) Generate the map (failure to do this can stop postfix working!) as follows:

postmap /etc/postfix/relocated

4) Restart postfix:

/etc/init.d/postfix restart

Note: if you edit /etc/postfix/relocated you need to rebuild the map database with "postmap /etc/postfix/relocated".