Do not use on any
shared computer
September 8, 2008 03:42am pdt
 
[x]
Attachment Details

Net::SMTP not sending CC correctly

Tags: perl, multiple
I'm having an issue wherein I can't get Perl's Net::SMTP module to send to multiple addresses.
Whichever address I put in the first "To:" entry is sent correctly, but I can't get CC to work.
I've also tried putting multiple addresses in the "To:" entry and experience the same results.

I can see the correct information in the email I receive via the first "To:" entry (ie. the email shows the CC entry properly) but the email is not sent to the second address regardless of where I place it.

Here is a snip of the Perl script where Net::SMTP is implemented:
--------------------------------------------------
sub send_mail {
  my ($smtp_to, $smtp_subject, $smtp_body, $smtp_cc1) = @_;
  my $smtp_host = 'x.x.x.x';   # masked ip (confidential)
  my $smtp_from = hostname."\@domain.com";   # masked domain (confidential)
  my $smtp_message;
  eval { $smtp_message = Net::SMTP->new($smtp_host) };
    if ($@) { warn "Unable to open the SMTP connection: $! <Net::SMTP->new($smtp_host)>" };
  eval { $smtp_message->mail($smtp_from) };
    if ($@) { warn "Unable to open the SMTP connection: $!<$smtp_from>" };
  $smtp_message->to($smtp_to);
  $smtp_message->data();
  $smtp_message->datasend("To: $smtp_to\n");
  $smtp_message->datasend("cc: $smtp_cc1\n") if (defined $smtp_cc1);
  $smtp_message->datasend("Subject: $smtp_subject\n");
  $smtp_message->datasend("\n");
  foreach my $smtp_body_line  (@$smtp_body) {
    chomp($smtp_body_line);
    $smtp_message->datasend("$smtp_body_line\n");
  }
  $smtp_message->dataend()
    or warn "Error in SMTP-dataend command: $!";
  $smtp_message->quit
    or warn "Error in SMTP-quit command: $!";
  warn "SMTP Message sent to $smtp_to with subject: $smtp_subject" if $trace_level > 1;
}


Here is the line where the email is sent:
--------------------------------------------------
send_mail('address1@domain.com', $lv_email_subject, \@la_email_body,'address2@domain.com')
  or warn "ATTENTION: send_mail subroutine failed: $!";

The mail server log only shows the first address as being received (no CC):
--------------------------------------------------
Aug 22 12:27:04 mailhost sendmail[10140]: [ID 801593 mail.info] l7MGR3Tt010139: to='address1@domain.com', delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=30845, relay=inbound.netidentit...rehostedemail.com. [ip address], dsn=2.0.0, stat=Sent (<46CC3A620005A3E7> Mail accepted)

However the header seems to be setup correctly as I can see the CC in the email I receive via the TO address:
--------------------------------------------------
From: hostname@domain.com [mailto:hostname@domain.com]
Sent: Wednesday, August 22, 2007 12:10 PM
To: address1@domain.com
Cc: address2@domain.com


I can flip the address1 and address2 back and forth and always receive only whichever is first in the TO/CC.
I've also tried using multiple "To:" entries in the send_mail subroutine (ie. 2 lines with "To:" in stead of "To:" and "cc:") and I experience the same issue - only the first address in the list is received (and I can see both entries in the header from the one email I receive)

I've tested CC using "mailx" on a unix system and it worked correctly, so there is no problem with the mail server itself.
FYI - The above perl scripts are running on a windows machine.
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: troesler
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by Adam314

Rank: Genius

Expert Comment by Adam314:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by troesler
Author Comment by troesler:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Adam314

Rank: Genius

Accepted Solution by Adam314:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by troesler
Author Comment by troesler:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Adam314

Rank: Genius

Expert Comment by Adam314:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628