--- y.orig 2009-09-29 21:11:50.544939894 +0200 +++ y 2009-09-29 21:31:44.072812281 +0200 @@ -4,27 +4,49 @@ # --------- use strict; use warnings; +use vars; use diagnostics; +use Data::Dumper; use MIME::Lite; use Email::Valid; # If we have a valid email address. - my $to_email = 'jakobi'; - my $email_valid = Email::Valid->new(mxcheck => 1,tldcheck => 1); - if ($email_valid->address($to_email)) { + my $to_email = 'jakobi@anuurn.compact'; + #my $email_valid = Email::Valid->new(mxcheck => 1,tldcheck => 1); + #if ($email_valid->address($to_email)) { + if (1){ + +# data dumper always shows an extra undef entry ??? +# bless( { +# 'SubAttrs' => {}, +# 'Parts' => [], +# 'FH' => undef, +# 'Attrs' => { +# 'content-disposition' => 'inline', +# 'content-type' => 'text/plain', +# 'content-length' => undef, +# 'content-transfer-encoding' => 'binary' +# }, +# 'Path' => undef, +# 'Data' => undef, +# 'Header' => [] +# }, 'MIME::Lite' ), +# and undef's seem to kill the send later on. +# to avoid this, **SET THE TYPE in ->build**! + + # Everything looks good, make up our message my $message = MIME::Lite->build ( From => $to_email, To => $to_email, Subject => 'This is the subject', - #Type => 'multipart/alternative' If I default to this then it never gets updated with a attachment. + Type => 'multipart/alternative' # If I default to this then it never gets updated with a attachment. ); # Did we get a attachment? - my $attachment = '/tmp/38293132401.pdf'; + my $attachment = '/etc/hosts'; + if (-e $attachment) { #$message->replace(Type => ''); # Tried this - #$message->replace(Type => 'multipart/mixed'); # Tried this - $message->add(Type => 'multipart/mixed'); + $message->replace(Type => 'multipart/mixed'); # Tried this + #$message->add(Type => 'multipart/mixed'); $message->attach( Type => 'AUTO', Path => $attachment, @@ -32,16 +54,22 @@ Disposition => 'attachment' ); } else { - $message->add(Type => 'multipart/alternative'); + # $message->add(Type => 'multipart/alternative'); } + my $text_email = 'yadda yadda yadda'; my $html_email = 'yadda yadda yadda'; # Do up the message - $message->attach(Type => 'TEXT', + $message->attach(Type => 'text/plain', # TEXT, but seems innocent and translates to text/plain Data => $text_email ); $message->attach(Type => 'text/html', Data => $html_email ); - $message->send('smtp','0.0.0.0',Debug=>1,Timeout=>60,Port=>26); - +warn "attach $attachment\n"; +warn "attach $attachment exists\n" if -e $attachment; +print Dumper($message); + my $rc=$message->send('smtp','0.0.0.0',Debug=>1,Timeout=>60,Port=>26); + # not reached, as we die due to lack of eval{} around send anyway!? + die "send returned not true" if not $rc; +}