Forum OpenACS Q&A: ns_senmail extraheaders errors-to:

Collapse
Posted by Bob OConnor on

We want to "beef" our users... we don't use no cheap spam!

Ok, many of our users are guests and some give us bogus addresses. We average over 350 new guests a week. When we "beef" 'em via ns_sendmail, the bounces and bogus addresses clog up the email box of the "cowboy" sender. I see from the docs on ns_sendmail:

http://www.aolserver.com/docs/tcldev/tapi-118.htm

    ns_sendmail to from subject body ?extraheaders? ?bcc?

    Description
    ns_sendmail sends a mail message with the specified to, from, and subject headers, and the specified body text. You can specify multiple "To:" recipients by providing a comma-separated list of email addresses in the to argument.

    You can add additional headers (such as an Errors-To header) by specifying the set ID of an ns_set that contains header name and content pairs in the extraheaders argument. On error, a Tcl error is signaled.

In my code I've tried:

set e_rrors "Errors-to: errors@rocnet.com"
 # Now inside the loop
 ns_sendmail $email $my_email $subject $body $e_rrors 

This does not work. The server.log shows:

Notice: Mail Failure: bob@rocnet.com 
Error: invalid set id: "Errors-to: errors@rocnet.com"

Ok, I'll bite, How do I make my set id valid?, AND I don't want to trigger a tcl error.

The ideal is that bounced messages go to an error mailbox and eventually when we get maildir working and code to link to the database, we could regularly process each message and if it were a bogus mailbox, delete the user from our system.

To start, I just want all bounces to go to a different address.

Thank you.
-Bob

I beef my users, might they get a virus and go mad?

Collapse
Posted by David Walker on
Do this
set extra_headers [ns_set create]
ns_set put $extra_headers Errors-to erroradmin@rocnet.com
ns_sendmail $email $my_email $subject $body $extra_headers
Collapse
Posted by Jonathan Marsden on
It seems that this code creates $e_rrors as a string variable, not an ns_set set. See http://www.aolserver.com/docs/tcldev/tapi-120.htm for docs on using ns_set. Something roughly like
set e_rrors [ns_set create]
ns_set update $e_rrors "Errors-to" "errors@rocnet.com"

might be closer to what you want to do, I think? There should be examples of this sort of usage in existing code... yes, ticket-defs.tcl does

    set extra_headers [ns_set create] 
    ns_set update $extra_headers "Reply-to" $ticket_email

In other words, that parameter to ns_sendmail is an ns_set, it is not a string.

Collapse
Posted by Matthew Braithwaite on
To start, I just want all bounces to go to a different address.

Then I am puzzled by why you want to mess with Errors-To, which is ``non-standard; discouraged'' according to RFC2076. What's wrong with sending your mail with an envelope sender of errors@rocnet.com? (I don't think ns_sendmail lets you set the envelope sender explicitly, but this is easy enough to fix.)

Collapse
Posted by Don Baccus on
You may want to go down to the _ns_sendmail level or lower.  ns_sendmail is a quick hack to let you do simple stuff easily, but isn't a full implementation of SMTP possibilities via its mapping of header information strategy.

On the other hand, ns_sendmail is built of pieces which build the socket, establish the SMTP connection, and send off the message with the appropriate SMTP headers.

You could plug into this without much trouble.  OACS 4 packages like acs-mail will before long and bypass the ns_sendmail shortcut entirely.