Difference between revisions of "Setting-up-postfix-for-sending-mail-using-an-external-SMTP-server"
(Created page with 'Setting up postfix for sending mail using an external SMTP server<br> Author: Eek <br>This how-to describes the setup of postfix for sending mail using an external SMTP server....') |
|||
Line 1: | Line 1: | ||
Setting up postfix for sending mail using an external SMTP server<br> | Setting up postfix for sending mail using an external SMTP server<br> | ||
Author: Eek | Author: Eek | ||
<br>This how-to describes the setup of postfix for sending mail using an external SMTP server. My ISP has a SMTP server available, for which i need (of course) to authenticate, using username and password.<br>Below is the configuration I will be using during the how-to, please replace it with your own. | <br>This how-to describes the setup of postfix for sending mail using an external SMTP server. My ISP has a SMTP server available, for which i need (of course) to authenticate, using username and password.<br>Below is the configuration I will be using during the how-to, please replace it with your own. | ||
<pre>smtp server : smtp.myisp.com | <pre>smtp server : smtp.myisp.com | ||
username : eek | username : eek | ||
password : thecat | password : thecat | ||
mailuser at myisp.com : eek@myisp.com | mailuser at myisp.com : eek@myisp.com | ||
mailuser on bubba : eek@bubba.excito.com</pre> | mailuser on bubba : eek@bubba.excito.com</pre> | ||
Packages<br>Install the packages, using the Debian sources, see Howto install Debian packages (http://forum.excito.net/viewtopic.php?t=421) | Packages<br>Install the packages, using the Debian sources, see Howto install Debian packages (http://forum.excito.net/viewtopic.php?t=421) | ||
<pre> | <pre>apt-get install postfix-tls | ||
apt-get install postfix-tls | apt-get install libsasl2-modules</pre> | ||
apt-get install libsasl2-modules</pre> | Setup<br>Edit the /etc/postfix/main.cf | ||
<pre>vi /etc/postfix/main.cf</pre> | |||
Look for the parameter relayhost and fill in your preferred smtp server | |||
Setup<br>Edit the /etc/postfix/main.cf | <pre>relayhost = [smtp.myisp.com]</pre> | ||
<pre> | Add the following parameters at the end | ||
vi /etc/postfix/main.cf</pre> | <pre>smtpd_sasl_auth_enable = no | ||
Look for the parameter relayhost and fill in your preferred smtp server | |||
<pre> | |||
relayhost = [smtp.myisp.com]</pre> | |||
Add the following parameters at the end | |||
<pre> | |||
smtpd_sasl_auth_enable = no | |||
smtp_sasl_auth_enable = yes | smtp_sasl_auth_enable = yes | ||
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd | smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd | ||
Line 29: | Line 23: | ||
smtp_sasl_security_options = noanonymous | smtp_sasl_security_options = noanonymous | ||
smtp_sasl_tls_security_options = noanonymous | smtp_sasl_tls_security_options = noanonymous | ||
smtpd_sasl_application_name = smtpd</pre> | smtpd_sasl_application_name = smtpd</pre> | ||
Create the sasl password file | Create the sasl password file | ||
<pre> | <pre>vi /etc/postfix/sasl_passwd</pre> | ||
vi /etc/postfix/sasl_passwd</pre> | Add the following contents | ||
Add the following contents | <pre># Contents of sasl_passwd | ||
<pre> | |||
# Contents of sasl_passwd | |||
# | # | ||
[smtp.myisp.com] eek:thecat</pre> | [smtp.myisp.com] eek:thecat</pre> | ||
Convert the file to a hash format | Convert the file to a hash format | ||
<pre> | <pre>postmap /etc/postfix/sasl_passwd </pre> | ||
postmap /etc/postfix/sasl_passwd </pre> | Check the above command by running a simple "hash" key test | ||
Check the above command by running a simple "hash" key test | |||
<pre>$ postmap -q [smtp.myisp.com] /etc/postfix/sasl_passwd | <pre>$ postmap -q [smtp.myisp.com] /etc/postfix/sasl_passwd | ||
</pre> | </pre> | ||
Protect your password so only root can read the file. | Protect your password so only root can read the file. | ||
<pre> | <pre>chmod 640 /etc/postfix/sasl_passwd</pre> | ||
chmod 640 /etc/postfix/sasl_passwd</pre> | <br> Mapping<br>Optional: Mapping local email address to valid Internet addresses. I created an account eek on the bubba and get default the email address eek@bubba.excito.com. <br>But my ISP knows me by eek@myisp.com, so i need to map the email addresses. | ||
Mapping<br>Optional: Mapping local email address to valid Internet addresses. I created an account eek on the bubba and get default the email address eek@bubba.excito.com. <br>But my ISP knows me by eek@myisp.com, so i need to map the email addresses. | |||
My postfix version is | My postfix version is | ||
<pre>$ postconf mail_version | <pre>$ postconf mail_version | ||
mail_version = 2.1.5</pre> | mail_version = 2.1.5</pre> | ||
For version 2.2 and later, you can use a generic file, see reference 4.<br>For version 2.1 and earlier, do the following:<br>Edit the /etc/postfix/main.cf | For version 2.2 and later, you can use a generic file, see reference 4.<br>For version 2.1 and earlier, do the following:<br>Edit the /etc/postfix/main.cf | ||
<pre> | <pre>vi /etc/postfix/main.cf</pre> | ||
vi /etc/postfix/main.cf</pre> | Add the following parameters at the end | ||
Add the following parameters at the end | <pre>canonical_maps = hash:/etc/postfix/canonical | ||
<pre> | virtual_alias_maps = hash:/etc/postfix/virtual</pre> | ||
canonical_maps = hash:/etc/postfix/canonical | Create the canonical file, which maps outgoing mail to a given email address | ||
virtual_alias_maps = hash:/etc/postfix/virtual</pre> | <pre>vi /etc/postfix/canonical</pre> | ||
Create the canonical file, which maps outgoing mail to a given email address | Add the following contents | ||
<pre> | <pre>eek@bubba.excito.com eek@myisp.com</pre> | ||
vi /etc/postfix/canonical</pre> | Create the virtual file, which maps incoming mail to a given email address | ||
Add the following contents | <pre>vi /etc/postfix/virtual</pre> | ||
<pre> | Add the following contents | ||
eek@bubba.excito.com eek@myisp.com</pre> | <pre>eek@myisp.com eek@bubba.excito.com</pre> | ||
Create the virtual file, which maps incoming mail to a given email address | Convert the files to a hash format | ||
<pre> | <pre>postmap /etc/postfix/canonical | ||
vi /etc/postfix/virtual</pre> | postmap /etc/postfix/virtual</pre> | ||
Add the following contents | <br> Restart<br>Restart postfix | ||
<pre> | <pre>/etc/init.d/postfix restart </pre> | ||
eek@myisp.com eek@bubba.excito.com</pre> | To see if all changes went into effect, run postconf -n | ||
Convert the files to a hash format | |||
<pre> | |||
postmap /etc/postfix/canonical | |||
postmap /etc/postfix/virtual</pre> | |||
Restart<br>Restart postfix | |||
<pre> | |||
/etc/init.d/postfix restart </pre> | |||
To see if all changes went into effect, run postconf -n | |||
<pre>$ postconf -n | <pre>$ postconf -n | ||
alias_database = hash:/etc/aliases | alias_database = hash:/etc/aliases | ||
Line 111: | Line 89: | ||
smtpd_sasl_auth_enable = no | smtpd_sasl_auth_enable = no | ||
smtpd_sasl_local_domain = $myhostname | smtpd_sasl_local_domain = $myhostname | ||
virtual_alias_maps = hash:/etc/postfix/virtual</pre> | virtual_alias_maps = hash:/etc/postfix/virtual</pre> | ||
<br> Test<br>Test if the mail is getting delivered<br>Login as eek | |||
<pre>su - eek</pre> | |||
Test<br>Test if the mail is getting delivered<br>Login as eek | Send mail | ||
<pre> | <pre>echo "Test mail" | mail -s "This is a test mail" eek@myisp.com</pre> | ||
su - eek</pre> | Check the logfile if the mail got handed to the smtp server | ||
Send mail | |||
<pre> | |||
echo "Test mail" | mail -s "This is a test mail" eek@myisp.com</pre> | |||
Check the logfile if the mail got handed to the smtp server | |||
<pre>$ cat /var/log/mail.log | <pre>$ cat /var/log/mail.log | ||
Dec 24 17:33:18 bubba postfix/postfix-script: starting the Postfix mail system | Dec 24 17:33:18 bubba postfix/postfix-script: starting the Postfix mail system | ||
Line 128: | Line 102: | ||
Dec 24 17:33:58 bubba postfix/qmgr[5105]: A45EA11F043A: from=<eek@myisp.com>, size=338, nrcpt=1 (queue active) | Dec 24 17:33:58 bubba postfix/qmgr[5105]: A45EA11F043A: from=<eek@myisp.com>, size=338, nrcpt=1 (queue active) | ||
Dec 24 17:33:59 bubba postfix/smtp[5113]: A45EA11F043A: to=<eek@myisp.com>, relay=smtp.myisp.nl[222.111.6.66], delay=1, status=sent (250 2.0.0 lBOGYki1012247 Message accepted for delivery) | Dec 24 17:33:59 bubba postfix/smtp[5113]: A45EA11F043A: to=<eek@myisp.com>, relay=smtp.myisp.nl[222.111.6.66], delay=1, status=sent (250 2.0.0 lBOGYki1012247 Message accepted for delivery) | ||
Dec 24 17:33:59 bubba postfix/qmgr[5105]: A45EA11F043A: removed</pre> | Dec 24 17:33:59 bubba postfix/qmgr[5105]: A45EA11F043A: removed</pre> | ||
Check if you've got mail!<br><br> References | |||
Check if you've got mail!<br> | |||
References | |||
1. http://souptonuts.sourceforge.net/postfix_tutorial.html<br> 2. http://www.postfix.org<br> 3. http://forum.excito.net/viewtopic.php?p=3060<br> 4. http://www.postfix.org/STANDARD_CONFIGURATION_README.html#fantasy<br> | 1. http://souptonuts.sourceforge.net/postfix_tutorial.html<br> 2. http://www.postfix.org<br> 3. http://forum.excito.net/viewtopic.php?p=3060<br> 4. http://www.postfix.org/STANDARD_CONFIGURATION_README.html#fantasy<br> |
Revision as of 11:27, 7 October 2010
Setting up postfix for sending mail using an external SMTP server
Author: Eek
This how-to describes the setup of postfix for sending mail using an external SMTP server. My ISP has a SMTP server available, for which i need (of course) to authenticate, using username and password.
Below is the configuration I will be using during the how-to, please replace it with your own.
smtp server : smtp.myisp.com username : eek password : thecat mailuser at myisp.com : eek@myisp.com mailuser on bubba : eek@bubba.excito.com
Packages
Install the packages, using the Debian sources, see Howto install Debian packages (http://forum.excito.net/viewtopic.php?t=421)
apt-get install postfix-tls apt-get install libsasl2-modules
Setup
Edit the /etc/postfix/main.cf
vi /etc/postfix/main.cf
Look for the parameter relayhost and fill in your preferred smtp server
relayhost = [smtp.myisp.com]
Add the following parameters at the end
smtpd_sasl_auth_enable = no smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtpd_sasl_local_domain = $myhostname smtp_sasl_security_options = noanonymous smtp_sasl_tls_security_options = noanonymous smtpd_sasl_application_name = smtpd
Create the sasl password file
vi /etc/postfix/sasl_passwd
Add the following contents
# Contents of sasl_passwd # [smtp.myisp.com] eek:thecat
Convert the file to a hash format
postmap /etc/postfix/sasl_passwd
Check the above command by running a simple "hash" key test
$ postmap -q [smtp.myisp.com] /etc/postfix/sasl_passwd
Protect your password so only root can read the file.
chmod 640 /etc/postfix/sasl_passwd
Mapping
Optional: Mapping local email address to valid Internet addresses. I created an account eek on the bubba and get default the email address eek@bubba.excito.com.
But my ISP knows me by eek@myisp.com, so i need to map the email addresses.
My postfix version is
$ postconf mail_version mail_version = 2.1.5
For version 2.2 and later, you can use a generic file, see reference 4.
For version 2.1 and earlier, do the following:
Edit the /etc/postfix/main.cf
vi /etc/postfix/main.cf
Add the following parameters at the end
canonical_maps = hash:/etc/postfix/canonical virtual_alias_maps = hash:/etc/postfix/virtual
Create the canonical file, which maps outgoing mail to a given email address
vi /etc/postfix/canonical
Add the following contents
eek@bubba.excito.com eek@myisp.com
Create the virtual file, which maps incoming mail to a given email address
vi /etc/postfix/virtual
Add the following contents
eek@myisp.com eek@bubba.excito.com
Convert the files to a hash format
postmap /etc/postfix/canonical postmap /etc/postfix/virtual
Restart
Restart postfix
/etc/init.d/postfix restart
To see if all changes went into effect, run postconf -n
$ postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases append_dot_mydomain = no biff = no canonical_maps = hash:/etc/postfix/canonical config_directory = /etc/postfix disable_vrfy_command = yes home_mailbox = Mail/ inet_interfaces = all mailbox_size_limit = 0 mydestination = $myhostname $mydomain localhost.$mydomain localhost mydomain = localdomain mynetworks_style = subnet myorigin = /etc/mailname recipient_delimiter = + relayhost = [smtp.myisp.nl] smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_sasl_tls_security_options = noanonymous smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) smtpd_helo_required = yes smtpd_recipient_restrictions = permit_mynetworks reject_unauth_destination reject_unauth_pipelining reject_invalid_hostname reject_non_fqdn_sender reject_unknown_sender_domain reject_non_fqdn_recipient reject_unknown_recipient_domain reject_rbl_client list.dsbl.org reject_rbl_client relays.ordb.org reject_rbl_client dnsbl.njabl.org reject_rbl_client dnsbl.sorbs.net reject_rbl_client bl.spamcop.net permit smtpd_sasl_application_name = smtpd smtpd_sasl_auth_enable = no smtpd_sasl_local_domain = $myhostname virtual_alias_maps = hash:/etc/postfix/virtual
Test
Test if the mail is getting delivered
Login as eek
su - eek
Send mail
echo "Test mail" | mail -s "This is a test mail" eek@myisp.com
Check the logfile if the mail got handed to the smtp server
$ cat /var/log/mail.log Dec 24 17:33:18 bubba postfix/postfix-script: starting the Postfix mail system Dec 24 17:33:18 bubba postfix/master[5100]: daemon started -- version 2.1.5 Dec 24 17:33:58 bubba postfix/pickup[5104]: A45EA11F043A: uid=1001 from=<eek> Dec 24 17:33:58 bubba postfix/cleanup[5111]: A45EA11F043A: message-id=<20071224173358.A45EA11F043A@bubba.localdomain> Dec 24 17:33:58 bubba postfix/qmgr[5105]: A45EA11F043A: from=<eek@myisp.com>, size=338, nrcpt=1 (queue active) Dec 24 17:33:59 bubba postfix/smtp[5113]: A45EA11F043A: to=<eek@myisp.com>, relay=smtp.myisp.nl[222.111.6.66], delay=1, status=sent (250 2.0.0 lBOGYki1012247 Message accepted for delivery) Dec 24 17:33:59 bubba postfix/qmgr[5105]: A45EA11F043A: removed
Check if you've got mail!
References
1. http://souptonuts.sourceforge.net/postfix_tutorial.html
2. http://www.postfix.org
3. http://forum.excito.net/viewtopic.php?p=3060
4. http://www.postfix.org/STANDARD_CONFIGURATION_README.html#fantasy