gezb has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Back to
Seekers of Perl Wisdom