Forum Moderators: coopster & phranque

Message Too Old, No Replies

PERL Sendmail BCC Not Working

BCC does not work

         

WWMike

2:20 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



The following script does not send any email to the BCC recipient. Any ideas why? Thanks in advance.

#!/usr/local/bin/perl
print "Content type: text/html\n\n";
open (SENDMAIL, "¦ /usr/sbin/sendmail -t");
print SENDMAIL "Subject: Test BCC\n";
print SENDMAIL "To: $ENV{SERVER_ADMIN}\n";
print SENDMAIL "From: $ENV{SERVER_ADMIN}\n";
print SENDMAIL "BCC: bcc\@$ENV{SERVER_NAME}\n\n";
print SENDMAIL "http://$ENV{SERVER_NAME}\n\n";
close (SENDMAIL);
exit;

wruppert

11:00 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



Looks ok to me. Are you sure the recipient address exists? Perhaps you should a hardcoded known email address and see if that works.

coopster

12:36 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, WWMike.

I agree, I always start testing with a hardcoded email address first, then insert my variables. Have you dumped those ENVironment variables to make sure they contain what you expect as well?

WWMike

7:19 pm on Jul 17, 2005 (gmt 0)

10+ Year Member



All environment variables are fine. I receive the TO but I don't receive the BCC or any error at the FROM. I originally tested it with hardcoded addresses but got the same results. I changed them to environment variables so that the script would be more portable in case anyone wanted to copy, paste and upload it to their own server to test it live for themselves (hint-hint).

MichaelBluejay

7:36 am on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are the To: and Bcc: addresses the same? Some mailservers will deliver only one copy if an identical message is addressed to the same user twice.

WWMike

4:43 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



Yup. The SERVER_ADMIN or TO and FROM are domain@domain.com and the BCC is bcc@domain.com. Both are valid addresses that accept mail but the bcc never gets anything from the script. I'm baffled.

Brett_Tabke

12:02 pm on Jul 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The above code looks ok to me and used about 20k times a day on WebmasterWorld..

I would back track and double check your variables:

- set a variable eq to the environ emails you are trying to use: eg:

$ty=$ENV{SERVER_ADMIN}

Then echo that to the screen as you use them in the script.



This is right out of our code here:

if (-e $mailprog) {
open(MAIL, "¦$mailprog -t");
print MAIL "To: $emailadr\n";
print MAIL "Bcc: $ebcc\n";
print MAIL "From: $fromemail\n";
print MAIL "Subject: Bill The Cat - Ack!\n\n";
print MAIL "$message";
close(MAIL);
}

WWMike

6:38 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



Well, I know you guys must think I'm stoopid but it still doesn't work. Here's what I have, pretty much copy & paste from above (the email addresses have been changed):

#!/usr/local/bin/perl

$mailprog = '/usr/sbin/sendmail';
$emailadr = 'to@mydomain.com';
$ebcc = 'bcc@mydomain.com';
$fromemail = 'from@mydomain.com';
$message = 'Test BCC';

if (-e $mailprog) {
open(MAIL, "¦$mailprog -t");
print MAIL "To: $emailadr\n";
print MAIL "Bcc: $ebcc\n";
print MAIL "From: $fromemail\n";
print MAIL "Subject: Test BCC\n\n";
print MAIL "$message";
close(MAIL);
}

print "Content type: text/html\n\n";

exit;

As you can see, each email address is different. I even ran the script twice and swapped the TO and BCC email addresses to make sure that they were both working (which they were) but still no BCC either way.

The only odd thing I noticed was that when I ran the script a third time and used TO and BCC email addresses that I know would bounce, I never got a bounce at the FROM even though I got one when I manually sent an email to the same invalid TO and BCC addresses using Outlook. Maybe that's normal for sendmail - I dunno - just thought maybe it would help all you headscratchers figure out who's to blame here.

MichaelBluejay

3:52 am on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm stumped. But if it were my problem I'd try BCC'ing to a completely different address on some other domain -- like Yahoo or Hotmail. That might provide some clues.

You could also try reversing the To: and Bcc: addresses to see what happens when you do that.

zCat

4:24 am on Jul 27, 2005 (gmt 0)

10+ Year Member



Which program is actually masquerading as sendmail on your system? Sendmail itself or something else like postfix? It's possible the behavior regarding Bcc might vary between systems.

moltar

5:11 am on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes BCC could have been disabled by your host to prevent spam.

WWMike

1:18 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



OK, first of all, many thanks to everyone that offered a suggestion - I tried them all.

Here's the deal:

When I send an email with a BCC to 5 different email addresses at some major domain that starts with a Y and provides web based email I get an email at each of the 5 accounts...

- but -

When I send an email with a BCC to 5 different email aliases at my own domain I only get 1.

Why?

Because they are not separate POP accounts like at the Y. They are all being forwarded to one account and somewhere along the line, the duplication gets filtered out.

I expected to get the 5 BCC's sent but in that scenario, getting just the 1 is actually more correct because there is only 1 physical account.

Granted, you guys couldn't see that and I couldn't either until I tried using completely separate domains.

The moral to be learned here is to make sure that your proposed test environment simulates the actual working environment as much as possble to eliminate the possibility of interpreting the results incorrectly.

The BCC was working all along - just not how I expected it to.

Special thanks to MichaelBluejay for suggesting separate domains which helped me resolve "the problem that wasn't"!