Lasso Soft Inc. > Home

[smtp_send8]

Linksmtp_send8
AuthorJohan Solve
CategoryEmail
Version8.x
LicensePublic Domain
Posted21 Dec 2006
Updated27 Dec 2006
More by this author...

Description

This is not a tag, but a patch of one of Lasso's built in datatypes which is used by [email_send].

This patch makes it possible to specify an alternate SMTP MAIL FROM address when sending email with the email_send tag, which lets you control where bounces go to. This lets you manage bounces more efficiently when doing mass mailings.

The patch is a modified version of the internal member tag email_smtp->send, which will override the built-in member tag when loaded from LassoStartup. Put smtp_send8.lasso in LassoStartup, then restart Lasso.

Specify the desired bounce-to address by adding a custom header "X-Bounce-to" when sending the message, like this:
-ExtraMIMEHeaders=(array: 'X-Bounce-to'='bounces@mydomain.se').
The bounce-to will be used as SMTP FROM address when sending the message. This address will be used as bounce address for well-behaving email systems. The SMTP FROM address is then added as Return-Path header at the top of the message headers by the receiving mail server when the message is delivered to a mailbox, so look for that header when verifying that the bounce address is right.
Please note that the added custom header will remain in the message after it is sent.

The patch works with Lasso 8.0 and 8.1. It it probably still needed for 8.5 but has not been verified yet. 

History
2005-01-03 Patch version 1.0 Johan Sölve
2005-04-12 Patch version 1.0.1 Johan Sölve
    Added unfolding of headers when looking for bounce address
2005-05-13 Updated for Lasso 8.0.4
2005-11-24 Updated to allow empty sender in X-Bounce-To
2006-12-21 Added version check for 8.5
2006-12-27 Corrected typo in version check for 8.5

Sample Usage

email_send: -from='sales@mydomain.se', 
    -to='all@customer.se', 
    -subject='Latest news from us',
    -body=$message,
    -ExtraMIMEHeaders=(array: 
        'X-Bounce-to'='bounces@mydomain.se');

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

= 8.5;
	log_critical: 'smtp_send8.lasso is only intended for Lasso 8.0 and 8.1 - not loading on ' + (lasso_version: -lassoversion);
	abort;
else;
	log_critical: 'smtp_send8.lasso custom version of smtp->send is loading';
/if;


// first create a prototype out of the original type

define_type('smtpbuiltin', 'email_smtp',
	-namespace = 'email_',
	-prototype);
/define_type;


// then subclass the prototype to replace the original, and redefining one of the member tags


define_type('smtp', 'email_smtpbuiltin',
	-namespace = 'email_');

	// ->Send
	// We send the message here
	define_tag('send',
		-required = 'from',
		-type = 'string',
		-required = 'recipients',
		-type = 'array',
		-required = 'message');

		local(
			'net' = @self->'net',
			'timeout' = @self->'timeout',
			'_message' = (string_replace: #message, -find='\r\n.', -replace='\r\n..'));

		if(!self->command(-send = 'RSET\r\n', -expect = 250));
			return(false);
		/if;

		//--------------------------------------------------
		// begin custom version by Johan Sölve
		
		
		local: 'js_smtp_from'=(string: #from),
			'js_smtp_from_header'='X-Bounce-to: ';

		// grab message headers
		local: 'js_headers' = ((string: #_message)->(split: '\r\n\r\n'))-> first;
		// unfold headers
		#js_headers=(string_replaceregexp: #js_headers, -find='\\r\\n\\s+', -replace='');
		// split message headers
		#js_headers = (#js_headers->split: '\r\n');
		// look for X-Bounce-To header
		iterate: #js_headers, (local: 'js_thisheader');
			if: #js_thisheader -> (beginswith: #js_smtp_from_header);
				#js_thisheader -> (removeleading: #js_smtp_from_header);
				// remove spaces in the data, if any (LP8.0.3 can add spaces in folded header data)
				#js_thisheader -> (replace: ' ', '');
				// check for reasonable address format
				// empty sender is allowed to be able to send bounce-like messages
				if: #js_thisheader == '' 
					|| (string_findregexp: #js_thisheader, -find='\\w+?@\\w+?\\.\\w+') -> size > 0;
					#js_smtp_from = #js_thisheader;
					#js_smtp_from -> trim;
					loop_abort;
				/if;
			/if;
		/iterate;
		#js_smtp_from = (string_replaceregexp: #js_smtp_from, -find='\\s', -replace='');
		
		// these lines are changed from the original
		if(!self->command(-send = 'MAIL FROM:<' #js_smtp_from '>\r\n', -expect = 250));
			return(false);
		/if;

		// end custom version by Johan Sölve
		//--------------------------------------------------


		iterate(#recipients, local('i'));
			if(!self->command(-send = 'RCPT TO:<' #i '>\r\n', -expect = 250));
				return(false);
			/if;
		/iterate;

		if(!self->command(-send = 'DATA\r\n', -expect = 354));
			return(false);
		/if;

		if(#net->wait(#timeout, net_waitwrite) == net_waitwrite);
			#net->write(#_message);
		/if;

		if(!self->command(-send = '\r\n.\r\n', -expect = 250));
			return(false);
		/if;

		return(true);
	/define_tag;


/define_type;

?>

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft