here's the problem (with all code - minus the comments)
I have an html document with a few thousand email addresses in it.
I need to extract these email addresses from the document and send an email
to each address (not send one email and cc everyone).
2 issues:
1) I need a better pattern for email addresses but I'm very weak in
syntax for regular expressions - is there a good place to learn more
about regex ??
2) the second script would run MUCH faster if I could put the open
and close commands to sendmail outside the loop and just
send an email to each address - I don't know how to send an eof to
sendmail though .. whenever I move the open and close outside the loop
sendmail creates an email message for each address in ONE message
and sends that one message to the first address. very discouraging
any ideas ?? please
script 1 - get the addresses
open ADDLIST, "addlist" or die "can't open file: $!";
@names = <ADDLIST>;
open NEWLIST, ">>emailist" or die "can't open file: $!";
foreach (@names) {
if ( $_ =~ /([^\s\@]{1,}\@[^\s\@]{1,})/) {
print NEWLIST $_;
}
}
script 2 - send the mail
$sendmail = "/usr/lib/sendmail -t";
open ADDRESS, "address.txt" or die "can't open file: $!";
@mail_to = <ADDRESS>;
open BODY, "message.txt" or die "can't open file: $!";
$content = <BODY>;
foreach (@mail_to) {
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL "To: $_ \n";
print SENDMAIL "From: csorensen\@uptimeresources.net \n";
print SENDMAIL "Subject: South African tourism survey \n";
print SENDMAIL "Content-type: text/plain \n\n";
print SENDMAIL $content;
close(SENDMAIL);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.