I am trying to send a .xlsx via SMTP. There is content in the email that is sent but i think there is something wrong with the encoding. Whenever i try to open the .xlsx from the email i get the message the file format or file extension is not valid and to verify that it has not bee corrupted.

I realized that something like mimelite might be easier but i would like to figure out the SMTP route as well.

Any help would be appreciated

my $to_email = "xxx\@imail.org"; our $smtp = Net::SMTP->new("smtp.xx.xx.com",Debug=>1); $smtp->mail("xxx\@imail.org"); $smtp->recipient("$to_email"); $smtp->data(); $smtp->datasend("To: $to_email\n"); $smtp->datasend("Cc: xxx\@imail.org\n"); $smtp->datasend("From: xxx\@imail.org\n"); $smtp->datasend("Subject: Annual Access Reviews\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-Type: multipart/mixed; boundary= \"*B +CKTR*\"\n\n"); # Send the body. $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: text/html\n\n"); $smtp->datasend("@$distinct_manager[3], \n\n"); $smtp->datasend("<div><b>As a manager your task at hand</b> is + the following:</div>"); $smtp->datasend("<p>These user access reviews must be complete +d and returned by 12/18/2015 XX.XX.2015(6).</p>"); $smtp->datasend("<p><b>Please email the completed spreadsheets + to emailaddress\@imail.org.</b></p>"); $smtp->datasend("<p><b>Please go to http://some_internal_websi +te on how to upload your completed spreadsheet(s).</b></p>"); $smtp->datasend("<div>Thank You,</div>"); $smtp->datasend("<div>Manager, ISSA Identity and Access Manage +ment</div>"); $smtp->datasend("\n"); $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: application/vnd.openxmlformats- +officedocument.spreadsheetml.sheet; name=\"$attachfile\" \n"); $smtp->datasend("Content-Transfer-Encoding: base64"); $smtp->datasend("Content-Disposition: attachment; filename =\" +$attachfile\"\n\n"); $smtp->datasend("\n"); open(DAT, $attachfile) || die("Could not open text file!"); binmode(DAT); my $data = do { local $/; <DAT> }; close DAT; $smtp->datasend($data); $smtp->datasend("\n"); $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit;

In reply to Net:::SMTP and Attaching a xlsx by deg01004

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.