I have what I thought would be a simple requirement. An online requests needs to generate an email message with a specifically formated .csv file attached. I am having trouble getting it to work though. If I run this I see that the base64 encoded string is created, but on the recieving end it's gone.
#!/usr/bin/perl use strict; use MIME::Base64; use MIME::QUotedPrint; use Mail::Sendmail; my $s=<<eos; foo, bar, baz, name, email, important note TRUE,FALSE,TRUE, JoeUser, joeuser1\@there.com, This is the bosses kid eos my $req=encode_qp("I need to make a request for this important person! +"); my $cn = "Joe User"; my $estr=encode_base64($s); print $req."\n"; print $estr; my %msg =(from => 'valid email address',to=>'valid email address',subj +ect =>'test of attachment'); my $boundary= "==========".time()."=========="; $msg{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; $msg{'body'}=<<eob; --$boundary Content-Type: text/plain Content-Transfer-Encoding: quoted-printable $req --$boundary Content-Type: text/csv Content-Tranfer-Encoding: base64 Content-Disposition: attachment; filename="account request for $cn.csv +" $estr --$boundary-- eob sendmail(%msg) or die "Sending failed Error: $Mail::Sendmail::error"; exit;
On the recieving end the message is empty with an attachment icon with the filename (zero bytes long), and in the message source the body of the message looks like:
MIME-Version: 1.0 --==========1596563290========== Content-Type: text/plain Content-Transfer-Encoding: quoted-printable --==========1596563290========== Content-Type: text/csv Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="account request for Joe Use +r.csv" --==========1596563290==========--
Looking at everything I've found for this, it should work...what am I missing. (note if I just do this:
#sending a plain text message, maybe sendmail is messed up?? my %msg2 =(from => 'avalidemailaddress',to=>'avalidemailaddress',subje +ct =>'plain email', body=>"just a quick note!"); sendmail(%msg2) or die "Sending failed Error: $Mail::Sendmail::error";
It works as expected...

In reply to Problems using Mail::Sendmail to include an attachment by desertrat

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.