PERL NET::SMTP Cc Bcc Help Needed

Posted on 2004-11-22
Last Modified: 2013-12-25
Ok, I know how to use Net::SMTP to send messages with a single recipient but I am having problems using $smtp->bcc(). I want to send to multiple recipients in the bcc field. I have tried variables and arrays but nothing seems to work.

A side note: some addresses are not delivered to. i.e. the mail sent from my script is never received. Any ideas where I should start to look?

my $ServerName = $smtpserver;
$smtp = Net::SMTP->new($ServerName, Debug => 0);

$smtp->mail( $from );
$smtp->to( $to );

$smtp->datasend("To:  $to\n");
$smtp->datasend("From:  $from\n");
$smtp->datasend("Date: $mdate\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: text/html\n");
$smtp->datasend("Content-Transfer-Encoding: 7bit\n");
Question by:Bob-Villa
    1 Comment
    LVL 2

    Accepted Solution

    This is from a script I use for automated invoicing. It emails the client and bcc's to myself. The syntax below is from the notes I made from my programming and testing senarios. Although I only BCC myself, I would not have left the note in place if it didn't work when I tested.

       $smtp->bcc($bcc, $anotherbcc, $onemorebcc);
       # to ( ADDRESS [, ADDRESS [...]] )
       # cc ( ADDRESS [, ADDRESS [...]] )
       # bcc ( ADDRESS [, ADDRESS [...]] )

       $smtp->datasend("From: $from\n");
       $smtp->datasend("To: $to\n");
    # build a subject string
       $SUBJECT="An email from us";
       $smtp->datasend("Subject: ".$SUBJECT."\n");
       $smtp->datasend("MIME-Version: 1.0\n");
       $smtp->datasend("Content-Type: text/html; charset=us-ascii\n");

       $smtp->datasend("Hope you are well.\n");
       $smtp->datasend("Have fun for the holidays\n");

       # dataend
       $smtp->dataend();    # NOT datasend!


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
    It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
    Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now