Forum OpenACS Development: Can't send mail from acs-mail-lite

Collapse
Posted by Steve Manning on
Hi

I'm trying to send a plain text email using acs-mail-lite. I've followed the recommendations in Jades thread https://openacs.org/forums/message-view?message_id=191961 but I keep running into an error.

I have cut my code down to a bare example .tcl page to illustrate the problem:

========================================================

set user_id [ad_conn user_id]

set package_id [ad_conn package_id]

set to_addr [db_string get_user_addr {select email from parties where party_id=:user_id}]
    
set from_addr [ad_system_owner]
set subject "ACS Mail-Lite Test"
    
set body "ACS Mail-Lite Test [clock format [clock seconds] -format "%x"]\n\nThis is a test mail from acs-mail-lite"
    
set header [ns_set new]
ns_set put $header "Content-Type" text/plain
    
acs_mail_lite::send \
    -to_addr $to_addr \
    -from_addr $from_addr \
    -subject $subject \
    -body $body \
    -extraheaders $header \
    -package_id $package_id

ns_return 200 "text/plain" "Mail Sent [clock format [clock seconds] -format "%x"]"
========================================================

This works fine and returns the Mail Sent text. When I look in the acs_mail_lite_queue table the message is waitin but everytime the sweeper runs I get the following error because the extraheaders column is not an ns_set.

[13/Jul/2004:21:59:13][16785.1101179824][-sched:13-] Error: no such set: Content-Type text/plain Message-Id <-1183370610.1089752278.oacs@steve.festinalente.co.uk>
no such set: Content-Type text/plain Message-Id <-1183370610.1089752278.oacs@steve.festinalente.co.uk>
    while executing
"ns_set size $extraheaders"
    (procedure "_ns_sendmail" line 11)
    invoked from within
"_ns_sendmail $smtp $smtpport $timeout $tolist $bcclist  $from $subject $body $extraheaders"
    (procedure "ns_sendmail" line 47)

I'm running oacs 5.10 with acs-mail-lite 1.0b2 straight out of the repository.

Any help gratefully received.

Steve

Collapse
Posted by Brad Duell on
That's funny that you bring this up, because I recently ran across this, and I thought perhaps it was just a misconfiguration on my end.

I finally decided to add the following to my aolserver/modules/tcl/sendmail.tcl file, just after the "## Insert extra headers, if any (not for BCC)" line in the _ns_sendmail proc:

## Insert extra headers, if any (not for BCC)"
if { ![empty_string_p $extraheaders] && [catch { [ns_set size $extraheaders] } ] } {
  set extra_headers [ns_set create]
  for {set i 0} {$i < [llength $extraheaders]} {incr i} {
      ns_set put $extra_headers [lindex $extraheaders $i] [lindex $extraheaders [expr $i + 1]]
      incr i
  }
  set extraheaders $extra_headers
}

This now works for me.

Anyone know why it seems we now have to kludge the sendmail proc?  Extraheaders is just kept as a list in acs-mail-lite.

Collapse
Posted by Steve Manning on
Thanks Brad thats the way I was heading but I thought I'd check to make sure I've not missed something before posting a bug. I can't see how extra_headers could be a set when its stored as a list on the table so something has gone pear shaped somewhere.

Does anyone have this working without modifying sendmail.tcl?

    Steve

Collapse
Posted by Jeff Davis on
It turns out the rewrite of acs-mail-lite ignored the acs-rollout-support stuff since it dispensed with the ns_sendmail call (acs-rollout-support redefined ns_sendmail to do it's magic). Jade put something back in to do rollout support but when he did he got the extraheaders bit wrong (since it's a list at that point). For ns_sendmail it's always been an ns_set and it's wrong to change it to try to treat it as a list if it's not an ns_set -- look for the comment about Rollout support in acs-mail-lite-procs.tcl in function deliver_mail and you will see where it's broken.
Collapse
Posted by Steve Manning on
Ah I see. In deliver_mail before the ns_sendmail line I add

set eh [util_list_to_ns_set $extraheaders]

and then replace $extraheaders with $eh in the ns_sendmail parameters.

Thanks Jeff. Later today I'll add that as a bug and patch if its not already there.

Steve

Collapse
Posted by Jeff Davis on
I committed a fix for this to HEAD. It should not happen on 5.1 since on 5.1 the acs-rollout-support stuff is still just ignored in acs-mail-lite. bcc also needs to be fixed but I think in rollout support the bcc is just ignored so maybe it does not matter.
Collapse
Posted by Steve Manning on
My version is straight out of the repository two days ago. A quick browse of the cvs shows that version 1.16 of acs-mail-lite-procs.tcl contains the fix but the repository is bringing back v1.15. Does 1.16 need to be tagged as openacs-5.1-compat for the repository to return it?

    Steve
Collapse
Posted by Jeff Davis on
I don't know why the openacs-5-1-compat tag is on HEAD rather than the 5.1 branch; that seems wrong to me. I moved the openacs-5.1-compat to 1.16 though so you should be able to update to pick up the fix.
Collapse
Posted by Jade Rubick on
Jeff, that was my fault. Before you and Joel clarified CVS practices for package developers, I was making changes on HEAD. So I had released acs-mail-lite from HEAD, by tagging it as openacs-5-1-compat. Of course, I won't do it that way in the future. Thank you for this fix.