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


In reply to Trying to send a nicely formatted email -> GMail by chexmix

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.