Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm need to send multiple attachments in an email but getting errors Bad or missing From address:

I have tried to fix these errors by setting mailcfg{from} address but then I get error No recipient!

I know sendmail is working as echo "test from sendmail" | /usr/sbin/sendmail myEmail@gmail.com from a terminal window sends an email

Email address is false as I don't want it displayed here, but it is a gmail account. Full code below

#!/usr/bin/perl use strict; use warnings; use Email::MIME; use Mail::Sendmail; #$Mail::Sendmail::mailcfg{'from'} = 'myEmail@gmail.com'; #$Mail::Sendmail::mailcfg{'recipient'} = 'myEmail@gmail.com'; # echo "test from sendmail" | /usr/sbin/sendmail myEmail@gmail.com my %attachments = ( 'doc_name' => 'contact_test.xls', 'doc_path' => '/home/docs/', 'doc_mime_type' => 'application/vnd.ms-exce +l', 'doc_template_name' => 'spreadsheet'); my @parts; push @parts, Email::MIME->create( attributes => { filename => $attachments{doc_path}.$attachments{doc_nam +e}, content_type => $attachments{doc_mime_type}, disposition => 'attachment', encoding => 'base64', name => $attachments{doc_name} } ); push @parts, Email::MIME->create( attributes => { content_type => 'text/plain', disposition => 'attachment', encoding => 'quoted-printable', charset => 'US-ASCII' }, body_str => 'this is the body' ); my $email = Email::MIME->create( header_str => [ From => 'myEmail@gmail.com', To => 'myEmail@g +mail.com', Subject => 'this is my subject' ], parts => [ @parts ] ); print $email->as_string; print "end of mail as_string\n"; my $response = sendmail($email); print "Response = $response\n"; print "error1 $!\n"; print "error2 $Mail::Sendmail::error\n"; print "Log\n", $Mail::Sendmail::log;

Output from running the script below

From: myEmail@gmail.com To: myEmail@gmail.com Subject: this is my subject Date: Wed, 14 May 2014 11:56:45 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1400065005.D7DeeC3a0.15978"; +charset="us-ascii" --1400065005.D7DeeC3a0.15978 Date: Wed, 14 May 2014 11:56:45 +0100 MIME-Version: 1.0 Content-Type: application/vnd.ms-excel; name="contact_test.xls" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="/home/docs/contact_test.xls +" --1400065005.D7DeeC3a0.15978 Date: Wed, 14 May 2014 11:56:45 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment this is the body= --1400065005.D7DeeC3a0.15978-- end of mail as_string Response = 0 error1 Bad file descriptor error2 Bad or missing From address: '' Log Mail::Sendmail v. 0.79_16 - Wed May 14 11:56:45 2014

Any help is appreciated


In reply to Sending email with attachments using Email::Mime by gezb

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (6)
    As of 2017-12-16 07:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (449 votes). Check out past polls.

      Notices?