Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Sending email with attachments using Email::Mime

by cord-bin (Friar)
on May 14, 2014 at 15:06 UTC ( #1086041=note: print w/replies, xml ) Need Help??

in reply to Sending email with attachments using Email::Mime

You need just a small change to your code, I tested on my machine and it works. You should change these lines and install Email::Sender::Simple module. I know the documentation of Email::MIME is not very clear on how to send actually the email. I use Email::Sender::Simple and works very fine, don't use the Mail::Sendmail. Here's the code:
#use Mail::Sendmail; print $email->as_string; print "end of mail as_string\n"; use Email::Sender::Simple qw(sendmail); my $response = sendmail($email); print "Response = $response\n"; print "error1 $!\n";

Replies are listed 'Best First'.
Re^2: Sending email with attachments using Email::Mime
by gezb (Novice) on May 14, 2014 at 21:28 UTC

    Thanks for your reply. I installed Email::Sender::Simple and changed the code as you suggested. A lot closer now. I am receiving the attachments but they are 0 file size so they cant open or save the documents from the email. I am also receiving the error `error1 Illegal seek` . Should not make any difference but I am using Ubuntu. Any ideas.

      Was curious to see what I might find about this: Not a great deal, but thought this was interesting in case you were using postfix:

      Postfix Illegal seek. Probably way outside of what your experincing... but then sometimes long shots pay off.

      Best of luck...

      ...the majority is always wrong, and always the last to know about it...
      Insanity: Doing the same thing over and over again and expecting different results...
      Ok, we are almost there, you need again a module and a very light change. I tried not to change your code too much just to get it work on my machine.
      You need to change, actually add one line to this part:
      use IO::All; # install this module first push @parts, Email::MIME->create( attributes => { filename => $attachments{doc_name}, content_type => $attachments{doc_mime_type}, disposition => 'attachment', encoding => 'base64', name => $attachments{doc_name} }, body => io($attachments{doc_name})->all, # add this line );
      For the illegal seek error, just delete these lines, you don't need them:
      #print "error1 $!\n"; #print "error2 $Mail::Sendmail::error\n";
      Cheers, have fun!

        Thats great, all working now. Thanks for your help and advice. This is why I love Perl !!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1086041]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-06-23 01:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.