Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Email To A List Of Addresses

by Milti (Beadle)
on Feb 02, 2017 at 21:59 UTC ( [id://1180892]=note: print w/replies, xml ) Need Help??


in reply to Re: Email To A List Of Addresses
in thread Email To A List Of Addresses

Thanks for the responses. The form that I'm using is on my office computer and not readily available (I hope) to anyone else. The cgi program is located on a remote server.You are correct in that I would like to simply paste a list into a text box on the form as something like this:

John Smith (john.smith@earthlink.net)
Bill Jones (bill_jones@hiscompany.com)
etc
etc

Then I would like to put the "lines/addresses" in an array and utilize a foreach loop to send individual emails.

Does this sound reasonable or do I have to worry about a delimiter?

Once again, thanks for any advice you can offer.

Replies are listed 'Best First'.
Re^3: Email To A List Of Addresses
by kennethk (Abbot) on Feb 02, 2017 at 23:34 UTC
    You have a delimiter there: newlines. Assuming they don't get passed through a layer that mangles white space at any point, it should work. Make sure to get your input box wide enough that you don't get bit by wrapping on
    John Smith (john.smith@earthlink.net) Bill Jones (bill_jones@hiscompany.com) Bill Jones (bill_jones@hisc +ompany.com) etc etc

    Note that the security problem is not with the machine that views the form, but with the remote server. Anyone on the Internet could craft an HTTP request to fool your remote server into sending messages unless you, say, configure Apache to whitelist only service requests from your machine. Right now you can operate because no one has found your service, but security-through-obscurity is not a good model. Other than helping a spammer, the other major risk is that a spammer gets your server blacklisted. And that's presuming they don't take advantage of some obscure sendmail bug to own your remote server.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re^3: Email To A List Of Addresses
by poj (Abbot) on Feb 03, 2017 at 13:24 UTC

    If all the email addresses are enclosed in brackets then perhaps use a simple regex to extract them. Here is a basic test script to play around with. The added confirm checkbox lets you test before actually sending.

    #!C:/Perl/bin/perl -w use strict; use CGI ':standard'; my $MAX = 10; # maximum in list my %list = (); my $confirm = param('confirm'); my $Email_List = param('Email_List'); # extract email adressess between () while ( $Email_List =~ m/\(([^)]+)/g ){ my $addr = $1; # remove spaces and any other cleaning here # assuming you don't have unusual addresses like # "Any Person"@somewhere.com $addr =~ s/ //g; # check valadity if ( is_valid($addr) ){ $list{$addr} = 'Not sent'; # using key avoids duplicates } } # check not too many my $msg; my $no = scalar(keys %list); if ($no > $MAX){ $msg = "ERROR - $no is too many to send"; } else { # send emails if confirm checked if ($confirm){ for (keys %list){ $list{$_} = send_to($_); # store result } } } # input form print header(), start_html; print qq!<h4>Recipients (maximum $MAX)</h4> <form action="" method="post"> <textarea cols="80" rows="20" name="Email_List"> $Email_List </textarea><br/> <br/> Confirm<input name="confirm" type="checkbox"/> <input type="submit" name="action" value="Send"/> </form><br/> <span style="background-color:#ffff00">$msg</span>!;
    poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-09-08 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.