How to Send Mail

A collection of tips on howto tweak your Bubba.
Post Reply
Eek
Posts: 372
Joined: 23 Dec 2007, 03:03
Location: the Netherlands

How to Send Mail

Post by Eek » 24 Dec 2007, 13:00

Hi,

This how-to describes the setup of postfix for sending mail using an external SMTP server.

NOTE: this how-to is now also available on the wiki http://wiki.excito.org/wiki/index.php/S ... MTP-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)

Code: Select all

apt-get install postfix-tls
apt-get install libsasl2-modules
Setup
Edit the /etc/postfix/main.cf

Code: Select all

vi /etc/postfix/main.cf
Look for the parameter relayhost and fill in your preferred smtp server

Code: Select all

relayhost = [smtp.myisp.com]
Add the following parameters at the end

Code: Select all

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

Code: Select all

vi /etc/postfix/sasl_passwd
Add the following contents

Code: Select all

# Contents of sasl_passwd
#
[smtp.myisp.com]       eek:thecat
Convert the file to a hash format

Code: Select all

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
eek:thecat
Protect your password so only root can read the file.

Code: Select all

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

Code: Select all

vi /etc/postfix/main.cf
Add the following parameters at the end

Code: Select all

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

Code: Select all

vi /etc/postfix/canonical
Add the following contents

Code: Select all

eek@bubba.excito.com      eek@myisp.com
Create the virtual file, which maps incoming mail to a given email address

Code: Select all

vi /etc/postfix/virtual
Add the following contents

Code: Select all

eek@myisp.com      eek@bubba.excito.com
Convert the files to a hash format

Code: Select all

postmap /etc/postfix/canonical
postmap /etc/postfix/virtual
Restart
Restart postfix

Code: Select all

/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

Code: Select all

su - eek
Send mail

Code: Select all

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!

Have Fun.

References
Last edited by Eek on 22 Jul 2011, 03:03, edited 1 time in total.

Hammer
Posts: 124
Joined: 02 Oct 2007, 13:37

Post by Hammer » 12 Jan 2008, 11:15

Phew, great effort but for me too advanced.

I use fetchmail to get mail from lots of accounts and would like to send via on of those, via my isp. That is, I don't have an email address "Myaddress@myisp.com", but another external. I must however logon to the smtp server to send.

If I don't want to use any bubba email account but another external email account, how would I do?

I got as far as
Quote:
$ postmap -q [smtp.myisp.com] /etc/postfix/sasl_passwd
eek:thecat
where I entered my own data, but the $ wasn't accepted, and neither was mylogin:mypwd on a new line. IT didn't work on the same line as the first either.



Cheers,
Hammer

pa
Posts: 308
Joined: 06 Dec 2006, 04:38
Location: Sweden
Contact:

Post by pa » 12 Jan 2008, 11:58

Have you entered the "$" sign? It is written on the command line by linux. Try it without to see what happens.

/PA

Post Reply