Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

CC with sendmail?

by htmanning (Pilgrim)
on Mar 23, 2020 at 00:43 UTC ( #11114553=perlquestion: print w/replies, xml ) Need Help??

htmanning has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I'm trying to send via Cc with sendmail. The first recipient receives the email and the headers look correct with a CC, but the email never makes it to the copied address.
open (MAIL, "|$sendmail $recipient") || die "Can't open $mailprog!\n" +; print MAIL "From: Return Address <$return_email>\n"; print MAIL "Reply-to: $return\n"; print MAIL "To: $recipient\n"; if ($email2) { print MAIL "Cc: $email2\n"; } print MAIL "Subject: Test!\n\n";
Is this even possible?

Replies are listed 'Best First'.
Re: CC with sendmail?
by dsheroh (Monsignor) on Mar 23, 2020 at 08:33 UTC
    When I send mail programmatically, I use a module to mediate the interaction with the MTA instead of trying to format all the headers and command-line parameters and so on correctly, so I don't know the full sendmail interface off the top of my head. But...
    open (MAIL, "|$sendmail $recipient") # ^^^^^^^^^^
    ...I strongly suspect that's your problem right there. You already told your sendmail to send the message to $recipient, so it's taking your word for it that that's where the mail should go, and not scanning the content of the mail for addresses. It's not even looking at the To: header, much less Cc: or Bcc:, because it already knows who the recipient is. If you just pipe the mail to sendmail without providing an address (or any other parameters) on the command line, I bet your cc will work as intended.

    Or, you know, find an email sending module on CPAN. There are... a few of them... to choose from, and they'll save you from tripping over little details like this and then having to figure out what you did wrong.

      This is the correct answer. Taking a look at sendmail, you could use the -t flag to also scan the message (to, cc, and bcc) to pick up those additional recipients.

Re: CC with sendmail?
by haukex (Bishop) on Mar 23, 2020 at 07:59 UTC

    I don't have a direct answer as to why sendmail with a CC might not work - but that's a very, very old way of sending mails. The first thing I would try, because it's easy to do, is replacing it with a modern module such as Email::Stuffer. If you then still have the same problem, it might be a configuration issue on the side of the mailer - but even in that case, using the aforementioned module makes things easy, since you can simply switch to a different transport by using a different Email::Sender implementation.

Re: CC with sendmail?
by pryrt (Monsignor) on Mar 23, 2020 at 01:27 UTC
    Did you look at rfc822 4.1, where it shows all lower case for cc: and bcc: ?
      Did you look at rfc822 4.1, where it shows all lower case for cc: and bcc: ?

      The same RFC also has section 3.4.7. CASE INDEPENDENCE, which says:

      When matching any other syntactic unit, case is to be ignored. For example, the field-names "From", "FROM", "from", and even "FroM" are semantically equal and should all be treated identically.
        Sorry, it's been 15+ years since I last used sendmail directly. :-)

        In skimming the rfc, I thought that

        The only syntactic units which requires preservation of case information are: text, qtext, ..., quoted-pair, ...
        implied that it was case sensitive, because quoted-string quoted-string = <"> *(qtext/quoted-pair) <"> includes quoted-pair, and "cc" was defined with quotes, so I assumed it was quoted-string, and thus required case sensitivity. Plus every instance of `cc:` in the rfc was all lower-case. But if `"From"` is explicitly not in that exception, and `"From"` and `"cc"` are defined with similar syntax, I obviously mis-remembered how to interpret those.

        And, after reading the rest of the replies, it's now readily apparent that the sendmail problem was really not specifying the other recipients where sendmail wants them, and the perl problem was not using a modern mail-sending module that are the root causes of the problem. :-) Thanks for the correction.

Re: CC with sendmail?
by akuk (Beadle) on Mar 26, 2020 at 05:14 UTC
    Can you try this:
    #!/usr/bin/perl use strict; use warnings; my $to ="recipent\"; my $cc = "copied\"; my $from = "noreply\"; my $subject = "You have got mail"; my $message = "Hello Admin\n\nHow are you doing today\n\nRegards,\n\An +onymous"; # send email using UNIX/Linux sendmail open(MAIL, "|/usr/sbin/sendmail -t"); ## Mail Header print MAIL "To: $to\n"; print MAIL "Cc: $cc\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n"; ## Mail Body print MAIL $message; # Close close(MAIL);
Re: CC with sendmail?
by htmanning (Pilgrim) on Mar 23, 2020 at 00:51 UTC
    I got it to work by adding both emails in the TO: field, but I cannot CC or BCC.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11114553]
Approved by kcott
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2022-05-18 14:28 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.