[tmpn tmp_seen][/tmpn][tmpn tmp_users][/tmpn]
[loop search="
fi=userdb
st=db
co=yes
op=rm
ml=1000
sf=mail_list
tf=lname
se=[cgi target_list]
rf=username,fname,lname,company,email,mail_list
"]
[loop-sub sent_check]
$tmp_url ||= $Tag->area({
href => '__UI_BASE__/customer_view',
form => "view=1",
});
$tmp_struct ||= $Scratch->{sent_ids} ||= {};
my $stuff = shift;
my $row = shift;
my $list = $CGI->{target_list};
my $user = $row->[0];
if (my $s = $tmp_struct->{$user}) {
return if $s =~ /\s$list\s/;
}
$Scratch->{tmp_seen}++;
if(! $CGI->{show_members}) {
$uary = $Scratch->{tmp_users} ||= [];
push @$uary, $user;
return;
}
my $url = $tmp_url . '&' . "customer=$user";
$stuff =~ s/HREF=""/href="$url"/;
return $stuff;
[/loop-sub][loop-exec sent_check]
[loop-param email] -- [loop-param fname] [loop-param lname][if-loop-param company], [loop-param company][/if-loop-param] (
[loop-code])
[/loop-exec][/loop]
[if scratch tmp_users]
{tmp_users}}; [/calc]"
type=hidden>
[/if]
[if !scratch tmp_seen]
You have already sent email to all users on this list. You should not send more
than one message per day at the very top! Once a month is more appropriate. Imagine
if someone sent you mail every day!
You will have to turn off your browser or cancel your session to send
mail to this list again. And it be on your head...
[/if]
[perl]
my @list = grep /\S/, split /[\s,\0]+/, $CGI->{produce};
my @messages;
my @out;
my $list = $CGI->{target_list};
my $opt = { table => 'userdb', hash => 1};
my $body = $Values->{mail_template};
$body =~ s/\r\n/\n/g;
$body =~ s/\r/\n/g;
$template = "From: $Values->{mail_from}\n";
$template .= "To: $Values->{mail_to}\n";
$template .= "Subject: $Values->{mail_subject}\n";
$template .= "Reply-To: $Values->{mail_reply}\n"
if $Values->{mail_reply} =~ /\w\w+/;
$template .= "\n$body";
my $burl = $Variable->{MAILING_UNSUB} || "$Config->{VendURL}/query/unsub";
for my $user (@list) {
$opt->{key} = $user;
my $record = $Tag->data($opt);
next unless $record;
$record->{mv_base_url} = $burl;
$record->{mv_email} = $Tag->filter('urlencode', $record->{email});
$record->{mv_list} = $list;
my $msg = $Tag->uc_attr_list($record, $template);
$msg =~ s/\s*$/\n/;
push @messages, [ $user, $msg ];
}
my $out;
return if ! @messages;
if($CGI->{direct_send}) {
my $max = $Variable->{MAIL_MAX_DIRECT} || 5;
if( scalar(@out) > $max ) {
my $msg = errmsg("Too many addresses for direct send, max %s!", $max);
return "
$max
";
}
my $s = $Scratch->{sent_ids} ||= {};
for(@messages) {
my ($u, $b) = @$_;
if( $s->{$u} =~ /\s$list\s/) {
push @out, errmsg("Already sent %s email to %s", $list, $u);
}
else {
my $msg = errmsg("Send to %s: ", $u);
my $opt = { raw => 1, body => $b };
if( $Tag->email_raw({}, $b) ) {
$msg .= errmsg('success');
$s->{$u} ||= '';
$s->{$u} .= " $list ";
}
else {
$msg .= errmsg('FAILED');
}
push @out, $msg;
}
}
$out = join "
\n", @out;
$Tag->log({
type => 'text',
file => 'logs/mailing',
body => join("\n",
$Tag->time({format => '%c'}),
"Sent mailing to list '$list':\n",
$template,
"\nResults:\n",
@out,
'####END MAILING ####',
''),
});
}
elsif($CGI->{download_batch}) {
@out = map { $_->[1] } @messages;
$out = "#!/bin/sh\n\ncat <
deliver( { body => \$out } );
$Tag->tmpn('delivered_mail_batch');
$Scratch->{delivered_mail_batch} = 1;
return;
}
else {
@out = map { $_->[1] } @messages;
my $divintro = q{};
my $divend = qq{\n};
$out = $divintro;
$out .= join "$divend$divintro", @out;
$out .= $divend;
}
return $out;
[/perl]
[/elsif]
[/if]
[if cgi show_close]