Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: How to send nicely formatted emails in Perl?

by zentara (Archbishop)
on Sep 08, 2012 at 09:43 UTC ( #992461=note: print w/replies, xml ) Need Help??

in reply to How to send nicely formatted emails in Perl?

Here is a pretty generic implementation of a program to mail html and text to a small list.
#!/usr/bin/perl use warnings; use strict; use MIME::Lite; use Net::SMTP; my @keys = qw(email name street city zip phone); my %recipients; my @fields; my $email; while(<DATA>){ @fields=(); ($email,@fields) = chomp && split(/\Q|\E/); # print "$email -> @fields\n"; $recipients{$email} = \@fields; } foreach my $key (keys %recipients){print "$key -> $recipients{$key}\n" +}; #for(keys %recipients){ #print "$_ has ",scalar @{$recipients{$_}}," stations and they are:\n" +; #for(@{$recipients{$_}}){ #print <<INFO; #Name: $_->[0] #Email: $_->[1] #Street 1: $_->[2] #City: i $_->[3] #State: $_->[4] #Zip: $_->[5] #Phone: $_->[6] #INFO #} #} #=head1 my $fromaddress = ''; foreach my $recipient (keys %recipients){ my $smtp = Net::SMTP ->new(''); $smtp->mail('you@yourdomain'); #use your mail name $smtp->to('reciever@recieverdomain'); $smtp->data( ); my $msg = MIME::Lite->new( From =>'Joe', To =>'Shmoe', Subject =>'HTML Test', Type =>'multipart/related', ); $msg->attach( Type => 'text/plain', Data => 'HERE IS YOUR HTML PAGE', ); $msg->attach( Type => 'text/html', #Path =>'full_file_name', Path => $0, Disposition => 'attachment', ); # send the message over $smtp->datasend( $msg->as_string() ); # close smtp connection $smtp->dataend(); $smtp->quit; } #=cut __DATA__|Zboo P. Crumbcake|1234 Main Street|San Francisco|C +A|94124|123-4567|Zebar X. Zipwon|3456 Second Ave.|San Francisco|C +A|94131|999-1234|Xbaz A. Fule|9123 Lost Road|Oakland|CA|97541|43 +1-4312 zentara@localhost|Ybong A. Gong|3456 Wain Street|San Francisco|CA|9413 +1|999-1234

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992461]
[Discipulus]: their?
[karlgoethebier]: marto: "their inability.." Perhaps the result of a wrong education?
[karlgoethebier]: or no education?
[choroba]: their = his or her
[Discipulus]: anyway once I proposed an automatic font decrease for post below -1, stepping every 5 votes: i'm still thinks it's a good idea but dunno if feasible
[shmem]: ...emulated dual in english
[shmem]: Discipulus: has that been in the CB? or in a PM node proper? for the latter case, can you provide the ID?
[Discipulus]: you seriously can use their in this way in eng?
[Corion]: Meh. $effin_bad_system has an interface breakdown and then loads events in parallel with events overtaking one another instead of being processed sequentially
[shmem]: Discipulus: dunno, but we do all the time ^^

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-05-23 08:19 GMT
Find Nodes?
    Voting Booth?