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

sendmail with perl

by mwhiting (Beadle)
on May 23, 2007 at 18:16 UTC ( [id://617075]=perlquestion: print w/replies, xml ) Need Help??

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

Hi - admittedly this is more like a sendmail question than a perl one, but just the same ....

Does sendmail (unix) process multiple email address on the To: line? I've been searching websites & tutorials & such for the answer and not found anything that really speaks directly to the issue (well, the sites/tutorials that do aren't working or aren't fully functional yet - aaaargh!)

What I get with a sendmail operation and the following line is:
To: abc@123.com, xyz@123.com

It only sends to the first email address on the line & ignores the rest. Doesn't matter which one is first.

Do I have to run it in a loop, one email at a time, or can I batch send them somehow? Thanks in advance.

Replies are listed 'Best First'.
Re: sendmail with perl
by jettero (Monsignor) on May 23, 2007 at 18:26 UTC

    In fact, I don't see a perl question at all. I think the answer somehow relates to the fact that the To: header is really part of the body of the message and the smtp "rcpt to:" command describes the actual recipients.

    If you want to do this in a perl way, look at Net::SMTP and MIME::Lite. And if you want to really really avoid work, see Net::SMTP::OneLiner.

    -Paul

      OK, I was a bit brief on the code that I actually use. Here's the perl code:
      $mailProg = "/usr/sbin/sendmail -t"; open (MAIL, "|$mailProg"); print MAIL "Date: $mailheader_date -0500\n"; print MAIL "To: $recipient\n"; print MAIL "From: $adminEmail\n"; print MAIL "Subject: Borrow Request\n"; print MAIL "***********************************\n"; (more print statements with the body of the msg in here) close (MAIL);

      So yes, it could be that I'm doing it the wrong way .... although this has worked for a long time on a lot of different servers. :)

      What call to the sendmail program would work then, if it should have something else for the envelope besides what's in the body?

        Yes, that works acceptably well. It's not wrong... It's not really perl though. And I definitely don't know how to send to more than one recipient that way. When I'm doing bigger jobs, I always use Net::SMTP. A lot of people like MIME::Lite too, so I'd check there. I believe it forks a sendmail in some modes.

        -Paul

Re: sendmail with perl
by zentara (Archbishop) on May 23, 2007 at 19:24 UTC
    Maybe Most efficient way to send mass email?

    Most people use MiME::Lite to avoid those hassles. I think the preferred way to do it is with a Bcc list, but your ISP may think you are spamming.

    #! /usr/bin/perl -w # #This program takes a list of email addresses and emails them. #NOTE: This program must be changed for each edition of the newsletter # use strict; use MIME::Lite; open(INDEX, "<index.htm") or die "Can't open index.htm file"; my $body = do { local $/; <INDEX> }; #Slurp the whole file in close(INDEX); my $msg = MIME::Lite->new( Subject =>'New phase of funding to support life-saving vaccines +', Type =>'multipart/related', ); $msg->attach(Type =>'text/html', Data =>$body, Disposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/Hivheader1.jpg', +Disposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/image001.jpg', Di +sposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/image002.jpg', Di +sposition=>'inline'); $msg->attach(Type =>'image/gif', Path =>'index_files/image003.gif', Di +sposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/image004.jpg', Di +sposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/image005.jpg', Di +sposition=>'inline'); $msg->attach(Type =>'image/jpg', Path =>'index_files/image006.jpg', Di +sposition=>'inline'); while (<>) { $msg->add(To=>"$_"); $msg->send("sendmail","/usr/bin/qmail-inject"); }; #while there are more address on the command line

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: sendmail with perl
by kyle (Abbot) on May 23, 2007 at 18:25 UTC

    I don't know how you're calling sendmail, but your example shows a RFC RFC 2822 header line. The SMTP protocol (RFC RFC 2821) actually considers those lines to be part of the body of the message and not really involved in delivery. The address used for delivery is normally called the envelope address, and that's passed on the sendmail command line.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-23 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found