Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net:SMTP - cc & bcc not working? 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Why does the CPAN doc along with many other web articles say you can use cc and bcc with Net:SMTP like so

Code:
 $smtp->cc('email@domain.com');
 $smtp->bcc('email@domain.com');
but when i do i get an error...
Code:
Can't locate object method "cc" via package "Net::SMTP"
Can't locate object method "bcc" via package "Net::SMTP"

does cc & bcc exist or not and if so what wrong with my syntax, because doing ...
Code:
 $smtp->to('email@domain.com');

works fine for a standard TO address. so why should cc & bcc not be working? any ideas.
 
lol - the missing " is only on this post not the code, I must have caught the delete key after cut/paste and editing for this post, sorry!

i might turn use strict and warnings off just to see if I can then do
Code:
 $smtp->bcc(@bcc);
without an error msg and see what happens.

it's a last resort!
 
As InDenial said, when you initialize your SMTP object, pass in the attribute Debug => 1 to see if there are any errors coming out of the SMTP server when you're sending your message.

- Rieekan
 
Was anything meant to happen after putting debug => 1 ?

nothing has changed, no emails to bcc.

I'm confused why you think this will make a difference.

If Indenial is right, that $smtp->datasend("Bcc: @Bcc\n"); just places the emails in the header then I assume $smtp->bcc(@bcc); is what sends the emails to the bcc recipients is that right?

I don't see how debug => 1 would make any difference if the code won't run with $smtp->bcc(@bcc) in it, and errors
Code:
 Can't locate object method "bcc" via package "Net::SMTP" (perhaps you forgot to load "Net::SMTP"?)



 
As stated in earlier replies, the $smtp->bcc(@bcc) is just a synonym for $smtp->recipient(@bcc), so you're not gaining anything by using the synonym.

The line $smtp->datasend("BCC: @bcc\n"); is where your gains are at. This line is sending the details of the message to the mail server, stating that you want certain addresses to appear in the To line of the recipient's e-mail, others in the CC (if used) and the last in the BCC, which will only show the address of the user that actually recieved the e-mail.

By turning on Debugging
Code:
my $smtp = Net::SMTP->new(SMTP_DOMAIN, Hello => SMTP_DOMAIN, Debug => 1) || die "Can't open mail connection: $!";
you'll gain the ability to see everything that transpires with the mail server to ensure your mail is being delivered correctly.

- Rieekan
 
Hello Rieekan,

Sorry if i'm seeming a bit dumb , but I've got InDenial saying $smtp->datasend("BCC: @bcc\n"); does nothing but put it in the header and I don't need it, and there's you saying that's where the gains are ?

I'm understanding what your saying, that it's the datasend which tells the smtp who goes where in the header and that bit is working, it's just people aren't getting any emails except those in the TO.

I'll give it one more try with it woking but the debug and see what happens.

 
I give up now no-one is getting the mail and i'm not getting any errors, it works if everyone goes in the TO and that will have to do.

unless you can see something wrong with my code

Code:
&send_mail("bob\@domain.com,sue\@domain.com","courses\@domain.com","Course Booking Confirmation","$body","joe\@domain.com");

sned mail like so
Code:
##############################
###### SENDMAIL ROUTINE ######
##############################

sub send_mail {

#############################
# Use Net::SMTP For mailing #
#############################

use Net::SMTP;

#_[0] = To
#_[1] = From
#_[2] = Subject
#_[3] = Body Text
#_[4] = Bcc

my (@Bcc, @Eadds, @recip);

# Create new instance of SMTP
my $smtp = Net::SMTP->new(SMTP_DOMAIN, Hello => SMTP_DOMAIN, debug => 1) || die "Can't open mail connection: $!";

# convert recipients to array from CSV
@recip = split(/\,/, $_[0]);

# add addressess together
push @Eadds, @recip;

# Check for Bcc
if($_[4] ne ""){
    @Bcc = split(/\,/, $_[4]);
    push @Eadds, @Bcc;
}

# Send Mail
$smtp->mail($_[1]);
$smtp->recipient(@Eadds);
$smtp->data();
$smtp->datasend("To: @recip\n");
$smtp->datasend("From: $_[1]\n");

if($_[4] ne ""){
    $smtp->datasend("Bcc: @Bcc\n");
}

$smtp->datasend("Subject: $_[2]\n");
$smtp->datasend("Content-type: text/html\n\n");
$smtp->datasend("$_[3]\n");
$smtp->dataend();
$smtp->quit();

}
 
nope this module doesn't work - i've just tried it on a completely different host and same thing - if i put ->bcc(@Bcc) i get the cant locate method error and i've tried every spelling permutation Bcc, bcc, BCC etc..

If I just send the lot as ->recipient(@eadds);

the two emails that are for the BCC field DO NOT GET THE EMAIL , but the others DO!

Here is the debug showing it should work

Code:
Net::SMTP=GLOB(0x17f2cac)<<< 220 easycgi.com ESMTP CommuniGate Pro 4.2.3 is glad to see you!
Net::SMTP=GLOB(0x17f2cac)>>> EHLO mail.easycgi.com Net::SMTP=GLOB(0x17f2cac)<<< 250-easycgi.com your name is not mail.easycgi.com
Net::SMTP=GLOB(0x17f2cac)<<< 250-HELP
Net::SMTP=GLOB(0x17f2cac)<<< 250-PIPELINING
Net::SMTP=GLOB(0x17f2cac)<<< 250-ETRN
Net::SMTP=GLOB(0x17f2cac)<<< 250-DSN
Net::SMTP=GLOB(0x17f2cac)<<< 250-TURN
Net::SMTP=GLOB(0x17f2cac)<<< 250-ATRN
Net::SMTP=GLOB(0x17f2cac)<<< 250-SIZE
Net::SMTP=GLOB(0x17f2cac)<<< 250-AUTH=LOGIN
Net::SMTP=GLOB(0x17f2cac)<<< 250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5 MSN
Net::SMTP=GLOB(0x17f2cac)<<< 250 EHLO
Net::SMTP=GLOB(0x17f2cac)>>> MAIL FROM:<test@stepnstomp.co.uk> Net::SMTP=GLOB(0x17f2cac)<<< 250 test@stepnstomp.co.uk sender accepted
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<dmo@dance-music.org> Net::SMTP=GLOB(0x17f2cac)<<< 250 dmo@dance-music.org will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<craig.chant71@ntlworld.com> Net::SMTP=GLOB(0x17f2cac)<<< 250 craig.chant71@ntlworld.com will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<sspl@stepnstomp.co.uk> Net::SMTP=GLOB(0x17f2cac)<<< 250 sspl@stepnstomp.co.uk will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<bollax@hotmail.com> Net::SMTP=GLOB(0x17f2cac)<<< 250 bollax@hotmail.com will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> DATA Net::SMTP=GLOB(0x17f2cac)<<< 354 Enter mail, end with "." on a line by itself
Net::SMTP=GLOB(0x17f2cac)>>> To: dmo@dance-music.org craig.chant71@ntlworld.com
Net::SMTP=GLOB(0x17f2cac)>>> From: test@stepnstomp.co.uk
Net::SMTP=GLOB(0x17f2cac)>>> Bcc: sspl@stepnstomp.co.uk bollax@hotmail.com
Net::SMTP=GLOB(0x17f2cac)>>> Subject: Testing
Net::SMTP=GLOB(0x17f2cac)>>> Content-type: text/html
Net::SMTP=GLOB(0x17f2cac)>>> This is a test
Net::SMTP=GLOB(0x17f2cac)>>> .
Net::SMTP=GLOB(0x17f2cac)<<< 250 54391763 message accepted for delivery
Net::SMTP=GLOB(0x17f2cac)>>> QUIT Net::SMTP=GLOB(0x17f2cac)<<< 221 easycgi.com CommuniGate Pro SMTP closing connection

does this mean there is a corrupt module floating around that many hosts must have installed or should I just give up with PERL now coz i'm never gonna get my head round how to make it work ?
 
OK, looking at the debug code, everything works just fine. All four addresses have been passed into the SMTP server for delivery:
Code:
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<dmo@dance-music.org> Net::SMTP=GLOB(0x17f2cac)<<< 250 dmo@dance-music.org will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<craig.chant71@ntlworld.com> Net::SMTP=GLOB(0x17f2cac)<<< 250 craig.chant71@ntlworld.com will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<sspl@stepnstomp.co.uk> Net::SMTP=GLOB(0x17f2cac)<<< 250 sspl@stepnstomp.co.uk will relay mail from a client address
Net::SMTP=GLOB(0x17f2cac)>>> RCPT TO:<bollax@hotmail.com> Net::SMTP=GLOB(0x17f2cac)<<< 250 bollax@hotmail.com will relay mail from a client address
And the message is accepted for delivery:
Code:
Net::SMTP=GLOB(0x17f2cac)<<< 250 54391763 message accepted for delivery
I would bet that your script has absolutely nothing wrong with it, but it's an issue with the two recipients' ability to receive an e-mail from one host (stepnstomp.co.uk) that is coming from a third party website (easycgi.com). I know hotmail has some spam blockers that prohibit this type of thing, but I couldn't say about the other site's host. Might be a good idea to look into.

Another thing you could try is to send the test to another account as a BCC note, but you could run into the same issue there.

- Rieekan
 
Hello Rieekan,

Nice try but I own all emails in question and know apart from the hotmail account as you say there is no reason I shouldn't get the emails.

No wonder I've been pulling my hair out this week, there is nothing wrong with my code, nothing wrong with the email addressess, so process of elimination leaves it to be either the module doesn't work or both hosts I have tried have either changed the module or blocked BCC at the SMTP server.

I beleive this is another of those attempts to stop people sending anonymous unsolicited email, at the expense of the damn thing working properly.

I have found this to be the case on another host before where the unix SENDMAIL had been blocked from sending BCC emails, I know this because it came up with a message stating the fact!

Oh well, thanks everyone for the replies, but I've wasted enough time chasing my tail on this one.

At least I can rest knowing for all those who pointed the finger at my code, I was not going mad, my code is fine :p


 
not sure about the net::smtp module but isn;t is possible to install the module in your own server space by copying the module there and doing a use lib? if so you can get your own module from cpan wich might work...

works with telnet.pm...

Anyway.. good luck in finding another solution.. too bad we were not able to help you make it work...

InDenial

 
it's OK, but if it isn't the module then it's the SMTP Server configuration, which I have no control over - so using the modlue outside of the install wont help.

It's no biggie , at least I can email with it for the moment - just not BCC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top