I've annoyed people in the CB with this for the past few days, so I might as well spread that annoyance around. Right, I'm trying to write a perl script to mass mail html email for my University's monthly Alumni bulletin. I'm stuck using only Net::SMTP (in short the way my University server is setup that's my only option). Here's what I have so far (any style pointers would be helpful also):

use Net::SMTP; #use Mail::Bulkmail; #Couldn't get this working on my U server #use Mime::Lite; #Server didn't like this my $mail_from = 'me@server.ca';< my @mail_to = ('1@server.com','2@server.com',...); my $subject = 'My subject eh'; my $count = 0; my $index = 0; my $message = q( <b>Some html text</b> ); #SMTP aliases to be reused to lessen the server load by not keeping ma +ny ports open my $smtp1 = Net::SMTP->new('my.mailserver.ca'); my $smtp2 = Net::SMTP->new('my.mailserver.ca'); my $smtp3 = Net::SMTP->new('my.mailserver.ca'); my $smtp4 = Net::SMTP->new('my.mailserver.ca'); while($index<=$#mail_to) { $smtp1->mail($mail_from); $smtp1->recipient($mail_to[$index]); $smtp1->data(); $smtp1->datasend("To: $mail_to[$index]\n"); $smtp1-> datasend ("Subject: $subject\n"); $smtp1-> datasend ("Mime-Version: 1.0\;\n"); $smtp1-> datasend ("Content-Type: text/html; charset='ISO-8859-1';\n\n +"); $smtp1->datasend($message); $smtp1->dataend(); $index++; $smtp2->mail($mail_from); $smtp2->recipient($mail_to[$index]); $smtp2->data(); $smtp2->datasend("To: $mail_to[$index]\n"); $smtp2-> datasend ("Subject: $subject\n"); $smtp2-> datasend ("Mime-Version: 1.0\;\n"); $smtp2-> datasend ("Content-Type: text/html; charset='ISO-8859-1';\n\n +"); $smtp2->datasend($message); $smtp2->dataend(); $index++; $smtp3->mail($mail_from); $smtp3->recipient($mail_to[$index]); $smtp3->data(); $smtp3->datasend("To: $mail_to[$index]\n"); $smtp3-> datasend ("Subject: $subject\n"); $smtp3-> datasend ("Mime-Version: 1.0\;\n"); $smtp3-> datasend ("Content-Type: text/html; charset='ISO-8859-1';\n\n +"); $smtp3->datasend($message); $smtp3->dataend(); $index++; $smtp4->mail($mail_from); $smtp4->recipient($mail_to[$index]); $smtp4->data(); $smtp4->datasend("To: $mail_to[$index]\n"); $smtp4-> datasend ("Subject: $subject\n"); $smtp4-> datasend ("Mime-Version: 1.0\;\n"); $smtp4-> datasend ("Content-Type: text/html; charset='ISO-8859-1';\n\n +"); $smtp4->datasend($message); $smtp4->dataend(); $index++; $count += 4; if($count == 40) { sleep(60); $count = 0; } } $smtp1->quit; $smtp2->quit; $smtp3->quit; $smtp4->quit; print "Mail sent succesfully, I think :)";
PS: I'm not sure if this is possible but can you send an email that will display html in html compatible email readers and text otherwise? (if so how would I encorporate this into my example)
PPS: No, I don't really what I'm doing :)

Edited by Chady -- added code tags.


In reply to Net::SMTP - mass mail by quelance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.