cowgod
cowgod

Reputation: 8656

How do I send an Email with no "to" address using Mail::Sender?

Is it possible to send an Email with only cc or bcc recipients using Mail::Sender? When I try to send an Email without a "to" address, I get the expected return code:

-8 = argument $to empty

Upvotes: 3

Views: 3805

Answers (3)

Jon Ericson
Jon Ericson

Reputation: 21515

Does the fake_to parameter work:

fake_to

=> the recipient's address that will be shown in headers. If not specified we use the value of "to".

If the list of addresses you want to send your message to is long or if you do not want the recipients to see each other's address set the fake_to parameter to some informative, yet bogus, address or to the address of your mailing/distribution list.

http://metacpan.org/pod/Mail::Sender

Looking at the source, it seems you'd still need to set the to parameter to something. Perhaps " " would do the trick?

Upvotes: 2

cowgod
cowgod

Reputation: 8656

Using an empty string '' in the "to" field does not work. Using a space works like a charm.

use Mail::Sender;

my $sender = Mail::Sender->new();
my $mail   = {
    smtp                 => 'mailserver',
    from                 => '[email protected]',
    to                   => ' ',
    bcc                  => '[email protected]',
    subject              => 'test',
    ctype                => 'text/plain; charset=utf-8',
    skip_bad_recipients  => 1,
    msg                  => 'test'
};

my $ret =  $sender->MailMsg($mail);

print $ret;

Upvotes: 4

TheTXI
TheTXI

Reputation: 37885

Have you tried using '' ?

Upvotes: -1

Related Questions