http://www.perlmonks.org?node_id=1213536

chexmix has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I'm working on a project where I'm going to need to send a decently-formatted table of things via email -- GMail, unfortunately, which I've found needs special lines for encoding the thing to "quoted-printable" to not destroy the nice formatting I've set up in the script.

The REAL script will get its data from a database, but I've put the following dummy script together to play with the modules I assume are necessary to get the email sent and look nice.

... and it's not working. I get blank emails with subject lines like "ARRAY(0x2730298)". I have futzed and futzed with the script-let below ... maybe a monk smarter than me (most of you) can tell me what I'm doing wrong.

#!/usr/bin/env perl use IO::All; use Email::MIME; use Email::Sender::Simple qw(sendmail); unlink 'mailtext.txt'; ################################################## # just an experiment with perlform to try and make # a nice output for the dashboard # ################################################ # set some vars so we can have stuff to print # what are we likely gonna wanna print? my $tweet_id = 0; my $tweet_cat = ''; # this is tweet category my $tweet_obj = ''; # this is tweet object: obsid? bibcode? my $tweet_obj_2 = ''; # secondary id - for instance, seq_nbr my $tweet_date = ''; my $tweet_weight = 0; open (MAILTEXT, '>>', 'mailtext.txt'); print(MAILTEXT "Content-Type: text/plain; charset=UTF-8\Content-Transf +er-Encoding: quoted-printable\n"); format TWIT = @<<<<<< @<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< @<< +<<<<<<<< ^<<<<<<<<< $tweet_id, $tweet_cat, $tweet_obj, $tweet_obj_2, $tweet_date, $tweet_w +eight ---------------------------------------------------------------------- +------------------------ . format TWIT_TOP = ====================================================================== +======================== twit_id twit_cat twit_obj twit_obj_2 dat +e_active twit_weight ====================================================================== +======================== . select(MAILTEXT); $~ = TWIT; $^ = TWIT_TOP; my @id = (50, 51, 52, 53, 54); my @cat = ("BIB", "BIB", "DAT", "PLE", "UNP"); my @obj = ("2014HEAD...1411609Z", "2016SPIE.9905E..45G","20201", "2 +018ApJ...855..100S", "19288"); my @obj_2 = (254, 29, 'X-ray Clusters', 5.1, 502938); my @date = ("02/02/18","03/23/18","03/22/18","03/13/18","03/05/18"); my @weight = (2, 5, 4, 3, 1); my $i = 0; foreach (@id) { $tweet_id = $_; $tweet_cat = $cat[$i]; $tweet_obj = $obj[$i]; $tweet_obj_2 = $obj_2[$i]; $tweet_date = $date[$i]; $tweet_weight = $weight[$i++]; write; } my @parts = ( Email::MIME->create( attributes => { filename => "mailtext.txt", content_type => "text/plain", encoding => "quoted-printable", name => "CDA Twitter Dashboard", }, body => io( "mailtext.txt")->utf8->all, ), ); my $email = Email::MIME->create( header_str => [ From => [ "cdatwitter\@grumble.edu" ], To => [ "gbecker\@grumble.edu" ], Subject => [ "Yes this is for Twitter" ], ], parts => [ @parts ], ); sendmail($email);

I'm sure the script sucks in many ways, but it's the emailing I'm concerned about here. Any nudges would be most appreciated.

Thanks,

Glenn