Jump to content

  •  

Photo
- - - - -

How to Install Postfix to work with Google Apps and Gmail

Debian 6

  • Please log in to reply
No replies to this topic

#1 Wilson18

Wilson18

    Administrator

  • root
  • 112 posts
  • LocationUniversity of Birmingham

Posted 22 June 2014 - 11:29 PM

For this to work, we have to install several packages and configure them. We start by typing

aptitude install postfix libsasl2 ca-certificate libsasl2-modules

Once you have done this, postfix will ask you how you would like to configure it. You will need to select Satellite System. You will then need to put in the System Mail Name. This would be your domain name. The following page will ask you for your SMTP Host Relay. If you are using google then this will be.

smtp.gmail.com

Now you will need to go in to and edit the postfix configuration file. If you dont know where this is or how to edit it then you can do so by typing

nano /etc/postfix/main.cf

When this file opens, there are a few changes you may want to make aswell as some essential ones. If you would not like any mail to be delivered locally then you will need to change where the line starts to mydestination and remove everything after the ‘=’ so you only have localhost. You will then need to add the following lines to the bottom of the file.

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Once you have done this, you can save and exit. The next thing we will be doing is creating the file which will be used to communicate the username and password to google to authenticate the account. to do this we need to type

echo '[smtp.gmail.com]:587 username@gmail.com:password' > /etc/postfix/sasl_passwd

Please note that if you are following this guide and pasting the contents in then it may replace the ‘ with a .  and it may not include the tab between 587 and your username so you will need to change these manually.

The next thing we need to do is make it so postfix can use these files and preventing other files from doing so etc. We do these by changing who can modify them with the chmod command. We will also be using the postmap command as well. Please type the following:

chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

The postmap command will map your username and password and add it to the database in an encrypted format. You can now remove this file should you wish it with the following command

rm /etc/postfix/sasl_passwd

The next thing we are going to do is to take care of a problem which you would experience if you were to restart postfix and try and use it as it is about not been able to authenticate. To fix this, we will need to run the following

cat /etc/ssl/certs/Equifax_Secure_CA.pem >> /etc/postfix/cacert.pem

Once you have done this, you should be good to go. You can now restart postfix.

service postfix restart

To test this we will create a php file and try and send an email using the phpmail function. To create this file, we can do the following however please make sure to change the information to your own.

echo '<?php $to = "YourEmail@Address.com"; $subject = "Successful Email Setup Confirmation"; $message = "Woop, Emails now work from your server!"; $headers = "From: <Username@Domain.tld>\r\n"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>' > /var/www/email.php

If you then type in

php /var/www/email.php

Then your email should be sent. You can check the error logs if you have any issues if you would like to try and work them out by typing:

nano /var/log/mail.log

List what you read?

Check me out on: YouTube, Twitter, Facebook, Google+






Also tagged with one or more of these keywords: Debian 6