resume writing services

Sendmail Howto

author Brad

The original instructions (kept below) for setting up DBMail with Sendmail were not easy to follow and possibly not complete/correct. I just installed DBMail using the instructions here quickly and easily:

As that website seems a little flakey, I will summarise the instructions here.

My install was with FreeBSD but will also work for Linux. I used FreeBSD's ports system to compile the source. I modified the Makefile to use the latest DBMail version. I am using MySQL.

Install as per usual, as documented on this website and on the helgrim.com link.

The following section is copied from the helgrim.com link for convenience.

Sendmail

Given the high flexibility of sendmail, there are many ways to use it with dbmail. The easiest method is to create a sendmail mailer definition for dbmail, and use the mailertable to deliver mail to dbmail on a per-domain basis. This still allows for normal local delivery for other domains.

Creating a mailer definition

First, you need to know the location of your sendmail sources. This can vary depending on OS distribtion. On FreeBSD, for example, it resides at /usr/share/sendmail/cf, whereas on OpenBSD it is /usr/share/sendmail.

If you are unsure, use a tool such as locate to search for mailer/local.m4, which should be in the main directory

    % locate mailer/local.m4
    /usr/share/sendmail/mailer/local.m4
    In this case, if is /usr/share/sendmail

Download the m4 config file available at http://www.helgrim.com/dbmaildocs/files/dbmail.m4 (shown below) and copy it into the mailer directory (eg /usr/share/sendmail/cf/mailer/dbmail.m4). This provides the definitions required to use dbmail as a mailer.

PUSHDIVERT(-1)
# 2003 Chrysalink Systems 
# Send feedback to dbmail@chrysalink.net
#

ifdef(`DBMAIL_MAILER_PATH',,
	`ifdef(`DBMAIL_PATH',
		`define(`DBMAIL_MAILER_PATH', DBMAIL_PATH)',
		`define(`DBMAIL_MAILER_PATH', /usr/local/sbin/dbmail-smtp)')')
_DEFIFNOT(`DBMAIL_MAILER_FLAGS', `SPhnu9')
ifdef(`DBMAIL_MAILER_ARGS',,
	`define(`DBMAIL_MAILER_ARGS', `dbmail -d $u')')

POPDIVERT

######################*****##############
###   DBMAIL Mailer specification   ###
##################*****##################

VERSIONID(`$Id: dbmail.m4,v 8.23 2003/07/14 13:48:51 feargal Exp $')

Mdbmail,	P=DBMAIL_MAILER_PATH, F=_MODMF_(CONCAT(`DFM', DBMAIL_MAILER_FLAGS), `DBMAIL'), S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP/HdrFromSMTP,
		ifdef(`DBMAIL_MAILER_MAX', `M=DBMAIL_MAILER_MAX, ')T=DNS/RFC822/X-Unix,
		A=DBMAIL_MAILER_ARGS

(Make sure you have the proper path to /usr/local/sbin/dbmail-smtp; dbmail-smtp may be installed elsewhere on your system).

Now you need to build a .cf file for sendmail to use. The exact process depends on your sendmail installation.

General

          # cd /etc/mail

Add the following line to your sendmail.mc file

          MAILER(dbmail)

Rebuild your sendmail.cf:

          # /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/ /usr/share/sendmail/m4/cf.m4 sendmail.mc > sendmail.cf

FreeBSD

Note by Andrea Brancatelli: To me the part about FreeBSD seems wrong. As soon as I have some time I'll write down the correct one. In the meantime pay attention and don't follow it blindly!

On FreeBSD, the mailer directory is in /usr/share/sendmail/cf.

          # cd /etc/mail

Add the following line to freebsd.mc:

          MAILER(dbmail)

Rebuild:

          # make freebsd.cf
          /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/ /usr/share/sendmail/cf/m4/cf.m4 freebsd.mc > freebsd.cf
          # make install
          install -m 444 freebsd.cf /etc/mail/sendmail.cf
          install -m 444 freebsd.submit.cf /etc/mail/submit.cf

SuSE Linux

On SuSE Linux, the mailer directory should be in /usr/share/sendmail.

          # cd /etc/mail

Add the following line to linux.mc:

          MAILER(dbmail)

Now create the sendmail.cf

          # /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/ /usr/share/sendmail/m4/cf.m4 linux.mc > linux.cf
          # cp linux.cf sendmail.cf

Configure the mailertable

Make sure your sendmail installation includes mailertable support. There should be a line in your sendmail.cf similar to:

    Kmailertable hash -o /etc/mail/mailertable

If not, you need to add the following to your .mc file, and rebuild your configuration as described above.

    FEATURE(mailertable, `hash -o /etc/mail/mailertable')

Edit the mailertable and add an entry for each domain you want to use dbmail with:

    domain.example.com dbmail:domain.example.com

Note, make sure domain.example.com is not in local-host-names or local-host-name, or sendmail will use local delivery instead.

Re-make your maps and restart sendmail

General:

    # makemap hash /etc/mail/mailertable.db < /etc/mail/mailertable
    # kill -HUP `head -1 /var/run/sendmail.pid`

FreeBSD:

    # cd /etc/mail
    # make maps
    # make restart

Finished

Complete the crontab to finish the install:

   00  3 * * * /usr/local/sbin/dbmail-util -ay

ORIGINAL INSTRUCTIONS:

Sendmail Howto based on Mike O'Brien instructions(from the mailling list):

author Marc

This howto is based on Debian, however should be portable to any other standard Sendmail install. To get dbmail-smtp of dbmail-lmtp to work, one needs to create new m4 macros. Create these files under /usr/share/sendmail/cf/mailer/

dbmail.m4:

PUSHDIVERT(-1)
ifdef(`DBMAIL_MAILER_PATH',,
	`ifdef(`DBMAIL_PATH',
		`define(`DBMAIL_MAILER_PATH', DBMAIL_PATH)',
		`define(`DBMAIL_MAILER_PATH', /usr/sbin/dbmail-smtp)')')
_DEFIFNOT(`DBMAIL_MAILER_FLAGS', `SPhnu9')
ifdef(`DBMAIL_MAILER_ARGS',,
	`define(`DBMAIL_MAILER_ARGS', `dbmail -d $u')')
POPDIVERT

Mdbmail,	P=DBMAIL_MAILER_PATH, F=_MODMF_(CONCAT(`DFM', DBMAIL_MAILER_FLAGS), `DBMAIL'), 
									S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP/HdrFromSMTP,
		ifdef(`DBMAIL_MAILER_MAX', `M=DBMAIL_MAILER_MAX, ')T=DNS/RFC822/X-Unix,
		A=DBMAIL_MAILER_ARGS

dbmail-lmtp.m4:

PUSHDIVERT(-1)
ifdef(`DBMAIL_MAILER_PATH',,
	`ifdef(`DBMAIL_PATH',
	`define(`DBMAIL_MAILER_PATH', DBMAIL_PATH)',
	`define(`DBMAIL_MAILER_PATH', [IPC])')')
_DEFIFNOT(`DBMAIL_MAILER_FLAGS', `AhmXz5@/:|')
ifdef(`DBMAIL_MAILER_ARGS',,
`define(`DBMAIL_MAILER_ARGS', `TCP $h 24')')

POPDIVERT
Mdbmail-lmtp,	P=DBMAIL_MAILER_PATH, F=_MODMF_(CONCAT(`DFM', DBMAIL_MAILER_FLAGS), `DBMAIL'), 
				S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP/HdrFromSMTP,
	ifdef(`DBMAIL_MAILER_MAX', `M=DBMAIL_MAILER_MAX, ')T=DNS/RFC822/X-Unix,
	A=DBMAIL_MAILER_ARGS

In dbmail-lmtp.m4 the connect port is set to port 24, change this if needed.

Then add the newly installed mailers and mailertable to /etc/mail/sendmail.mc:

FEATURE(`mailertable')dnl
MAILER(dbmail)dnl
MAILER(dbmail-lmtp)dnl

Now we have to tell sendmail to use the dbmail or dbmail-lmtp mailer for a given domain, otherwise it wil be handled as localmail. Assuming dbmail-lmtp is running on localhost. Edit /etc/mail/mailertable:

foo.com   dbmail-lmtp:[127.0.0.1]
bar.com   dbmail

Type make in /etc/mail, and reload your sendmail. Then test your configuration. Virtusertable and accesstable should work as with local mailers.

Setting up SMTP Auth with sasl2 and PostgreSQL

Add the following to sendmail.mc

include(`/etc/mail/sasl/sasl.m4')dnl

Then edit /etc/mail/sasl/Sendmail.conf.2 assuming the dbmail database runs on localhost. It is possible to add multiple databases in the configfile. On BSD systems it is located at /usr/local/lib/sasl2/Sendmail.conf

pwcheck_method: auxprop
auxprop_plugin: sql
sql_engine: pgsql
mech_list: DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
Sql_hostnames: localhost[:port]
sql_user: dbmail
sql_passwd: [password]
sql_database: dbmail
sql_verbose: yes
sql_select: SELECT passwd FROM dbmail_users WHERE userid = '%u'

Type make in the /etc/mail directory to update sendmail.cf and reload sendmail. Test your configuration. /var/log/auth.log gives plenty information when authentication fails.

dbmail as the local mailer

This allows you to use dbmail as the local delivery agent. With this configuration you will not use the system alias file and you will have to transcribe those int atmail.

in sendmail.mc add the lines:

FEATURE(`stickyhost')dnl

MAILER(dbmail-local)dnl
define(`MAIL_HUB',`dbmail-local:localhost')dnl

under /usr/share/sendmail-cf/mailer/ create dbmail-local.m4

PUSHDIVERT(-1)
	ifdef(`DBMAIL_MAILER_PATH',,
       `ifdef(`DBMAIL_PATH',
       `define(`DBMAIL_MAILER_PATH', DBMAIL_PATH)',
       `define(`DBMAIL_MAILER_PATH', [IPC])')')
_DEFIFNOT(`DBMAIL_MAILER_FLAGS', `hmXz@/:|')
ifdef(`DBMAIL_MAILER_ARGS',,
`define(`DBMAIL_MAILER_ARGS', `TCP $h 24')')
POPDIVERT
Mdbmail-local,  P=DBMAIL_MAILER_PATH, F=_MODMF_(CONCAT(`DFM', DBMAIL_MAILER_FLAGS), `DBMAIL'),S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP,
                T=DNS/RFC822/SMTP, 
                A=DBMAIL_MAILER_ARGS

(ensure that there are no extra spaces before lines; sendmail is very finnicky when it comes to it’s sendmail.cf)

add your local domains to local-host-names

Type make in /etc/mail, and reload your sendmail. Then test your configuration.

Michael Luich

 
sendmail_howto.txt · Last modified: 2011/08/02 10:24 by brittneylandry
 
DBMail is developed by Paul J Stevens together with developers world-wide