[ILUG] Programmatic mail sending with Postfix

Philip Reynolds philip.reynolds at rfc-networks.ie
Wed Apr 7 12:11:59 IST 2004


Colm Buckley <colm at tuatha.org> 30 lines of wisdom included:
> I investigated this in 2002, and was unable to find an easy way to make 
> Postfix do this.  In theory, all that is necessary is to drop files 
> into Postfix's "maildrop" directory and then signal the queue runner.  
> However, the maildrop directory contains files in a Postfix internal 
> format rather than in RFC822 format.
> 
> The approach to take would be to abstract the routines from postdrop 
> which convert RFC822 files to internal files, and use these in your 
> program.  We decided that this would be more hassle than it's worth.

It's also not recommended as the Postfix internals could change at
any time.

The best way to do this is via SMTP pipelining:


	220 XXXXX.rfc-networks.ie ESMTP Postfix
	EHLO XXXXXX.rfc-networks.ie
	250-XXXXX.rfc-networks.ie
	250-PIPELINING
	250-SIZE 10240000
	250-VRFY
	250-ETRN
	250-XVERP
	250 8BITMIME
	MAIL From: <philip.reynolds at XXXXXXXXXXXXXXX>
	250 Ok
	RCPT To: <test at XXXXXXXXXXXXXXX>
	250 Ok
	RCPT To: <philip.reynolds at XXXXXXXXXXXXXXX>
	250 Ok
	RCPT To: <john at XXXXXXXXXX>
	250 Ok
	RCPT To: <pat at XXXXXXXXXXXXXXX>
	250 Ok
	DATA
	354 End data with <CR><LF>.<CR><LF>
	Subject: Great good Marketing Gizmo!
	
	Hello ... hello ... hello!
	.
	250 Ok: queued as 8A5445CE0

All of the server commands are preceded with the status number (e.g.
250, 354 etc.)

SMTP multi-line commands are specified by using a -

i.e.

250-
250- 
250-

is all one response.

This is the most efficient method of sending mail via Postfix. If
your mails are all going to be unique, simply set up N SMTP
connection to send X number of mails (X will depend on your Postfix
setup). 

In this instance postdrop is not your friend.
-- 
Philip Reynolds                      | RFC Networks Ltd.
philip.reynolds at rfc-networks.ie      | +353 (0)1 8832063
http://people.rfc-networks.ie/~phil/ | www.rfc-networks.ie


More information about the ILUG mailing list