frank1 has asked for the wisdom of the Perl Monks concerning the following question:

I had a problem of sending emails with Bcc, and not getting delivered. but today i have read my smtp provider documentation and doesnt allow bcc

so i want to send each email using looping method to send each email separately to avoid recipients seeing other receivers

i have added this to my script to loop

my $RCPT; foreach $RCPT ($tostring) { }

the response is

no recipients
my $AID = "XD4555"; my $query = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID WHERE (m.USERID_IM = ?)"); $query->execute($AID); my $user1 = $query->fetchall_arrayref(); my $query_other = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID_IM WHERE (m.USERID = ?)"); $query_other->execute($AID); my $user2 = $query_other->fetchall_arrayref(); my $TotalEmails = [ @$user1, @$user2 ]; my @to; for my $em ( @$TotalEmails ) { push @to, @$em; } my $tostring = join ',', @to; my $RCPT; foreach $RCPT ($tostring) { } my $message_s = "<p>hi just test</p>"; my $smtpserver = 'smtp.xxxxxx.com'; my $smtpport = 587; my $smtpuser = 'xxxxx'; my $smtppassword = 'xxxxx'; my $transport = Email::Sender::Transport::SMTP->new({ host => $smtpserver, ssl => 'starttls', port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, }); my $email_s = Email::Simple->create( header => [ To => $RCPT, From => 'xxx@xxxx.com', Subject => "test hi", 'Content-Type' => 'text/html', ], body => $message_s, ); sendmail($email_s, { transport => $transport });

Replies are listed 'Best First'.
Re: sending batch of emails by looping
by karlgoethebier (Abbot) on Jul 26, 2023 at 19:33 UTC

    Your recipients should be in @to which I would rename to @recipients and then:

    for my $recipient(@recipients) { mail($recipient); } sub mail { my $recipient = shift; …; }

    Add more args to your sub, like $from, $message, $transport etc.

    «The Crux of the Biscuit is the Apostrophe»

      Thank you so much, this has solved my problem, thanks so so so much

Re: sending batch of emails by looping
by afoken (Chancellor) on Jul 27, 2023 at 11:30 UTC

    Third part of the same problem (Part 1, part 2).

    Please don't open new threads for every little detail of your problem. New threads don't show the context of your problem, and that wastes time of people willing to help.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)