Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Problems using Mail::Sendmail to include an attachment

by desertrat (Sexton)
on Aug 04, 2020 at 17:58 UTC ( [id://11120287]=perlquestion: print w/replies, xml ) Need Help??

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

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...

Replies are listed 'Best First'.
Re: Problems using Mail::Sendmail to include an attachment
by hippo (Bishop) on Aug 04, 2020 at 20:41 UTC
    use MIME::QUotedPrint;

    That isn't a module on CPAN - you probably meant MIME::QuotedPrint. Regardless, this suggests that the code you have entered in your post is not the code which you are running. This makes it pretty close to impossible for another party to debug.

    All that said, at least one error is that you are not separating the MIME headers from the bodies. Perhaps inserting that extra whitespace in your message is all you really need.

    $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

    🦛

      The MIME::QuotedPrint error was a typo introduced in a later edit of my post; it was referenced correctly in my program. It was the missing white space that was causing the issue. Thank you very much!
Re: Problems using Mail::Sendmail to include an attachment
by haukex (Archbishop) on Aug 05, 2020 at 20:11 UTC

    Since it sounds like this is a new script, it might be easier to use one of the more modern modules; see the Email::* modules by RJBS - I'd suggest you give Email::Stuffer a try.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11120287]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found