use BSE::ComposeMail for interest.pl and lost password emails
authorAdrian Oldham <adriann@visualthought.com.au>
Sun, 15 May 2011 01:49:58 +0000 (11:49 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 16 May 2011 01:31:05 +0000 (11:31 +1000)
site/cgi-bin/interest.pl
site/cgi-bin/modules/BSE/UserReg.pm

index b429d9c..78051c3 100755 (executable)
@@ -6,7 +6,6 @@ use FindBin;
 use lib "$FindBin::Bin/modules";
 use Constants qw(:shop);
 use BSE::Session;
-use BSE::Mail;
 use BSE::Template;
 use BSE::Util::Tags;
 use BSE::Request;
@@ -34,8 +33,17 @@ if ($useremail !~ /.\@./) {
 }
 
 # in theory we have an email address at this point
-my $mailer = BSE::Mail->new(cfg=>$cfg);
-my $sendto = $cfg->entry('interest', 'notify', $SHOP_FROM);
+require BSE::ComposeMail;
+my $mailer = BSE::ComposeMail->new(cfg => $cfg);
+
+my $email = $cfg->entry('interest', 'notify', 
+                         $Constants::SHOP_FROM);
+$email ||= $cfg->entry('shop', 'from');
+unless ($email) {
+  print STDERR "No email configured for interest notify, set [interest].notify\n";
+  return;
+}
+#
 my $product = $cgi->param('product');
 defined($product) or $product = '';
 my $product_id = $cgi->param('product_id');
@@ -50,16 +58,14 @@ my %acts;
    email => sub { $useremail },
   );
 
-my $content = BSE::Template->get_page('admin/interestemail', $cfg, \%acts);
-
 my $subject = "User registered interest";
 $subject .= " in product '$product'" if $product;
-if ($content =~ s/^subject:\s+([^\n])\r?\n\r?//i) {
-  $subject = $1;
-}
 
-$mailer->send(to=>$sendto, from=>$SHOP_FROM, subject=>$subject, 
-             body => $content)
+$mailer->send(template => 'admin/interestemail',
+    acts => \%acts,
+    to=>$email,
+    from=>$email,
+    subject=>$subject)
   or error_page('', "While sending email: ".$mailer->errstr);
 
 BSE::Template->show_page('interest/confirm', $cfg, \%acts);
index 9d35df3..d03db30 100644 (file)
@@ -1658,9 +1658,8 @@ sub req_lost_password {
       $email_user = $custom->send_user_email_to($user, $cfg);
     };
   }
-  require 'BSE/Mail.pm';
-
-  my $mail = BSE::Mail->new(cfg=>$cfg);
+  require BSE::ComposeMail;
+  my $mail = BSE::ComposeMail->new(cfg => $cfg);
 
   my %mailacts;
   %mailacts =
@@ -1670,14 +1669,16 @@ sub req_lost_password {
      site => sub { $cfg->entryErr('site', 'url') },
      emailuser => [ \&tag_hash_plain, $email_user ],
     );
-  my $body = BSE::Template->get_page('user/lostpwdemail', $cfg, \%mailacts);
   my $from = $cfg->entry('confirmations', 'from') || 
     $cfg->entry('basic', 'emailfrom') || $SHOP_FROM;
   my $nopassword = $cfg->entryBool('site users', 'nopassword', 0);
   my $subject = $cfg->entry('basic', 'lostpasswordsubject') 
     || ($nopassword ? "Your options" : "Your password");
-  $mail->send(from=>$from, to=>$email_user->{email}, subject=>$subject,
-             body=>$body)
+  $mail->send(template => 'user/lostpwdemail',
+               acts => \%mailacts,
+               from=>$from,
+               to=>$email_user->{email},
+               subject=>$subject)
     or return $self->req_show_lost_password($req,
                                        $msgs->(lostmailerror=>
                                                "Email error:".$mail->errstr,