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

Hi,

I'm trying to send an email to someone using, using MIME::Lite, to send via GMail SMTP. This is the code I have:
my $from = 'xxx <coo@site.net>'; my $to = 'tester <me@gmail.com>'; my $subject_val = "Your recent order"; my $contents = qq|Thanks for your order. Please find your invoice +attached.|; my $write_path = "/srv/www/site.net/www/cgi-bin/admin/invoice_pdfs +/generator/created_invoices/403-8079250-7569948.pdf"; my $file_name = "403-8079250-7569948.pdf"; my $pt = 587; # or 587, 465, etc depending on what gmail uses my $mailer = new Net::SMTP::TLS( $CFG->{db_smtp_server}, Port => $pt, User => $CFG->{db_smtp_user}, Password => $CFG->{db_smtp_pass}, Timeout => 60, ) or die "Cannot create a TLS mailer instance!\n"; $mailer->mail($from); $mailer->to($to); $mailer->data(); my $msg = MIME::Lite->new( From => $from, 'Reply-to' => $from, To => $to, Subject => $subject_val, Type => 'multipart/related' ) or die "Cannot create a new email instance!\n"; $msg->attach( Type => 'TEXT', Data => $contents, ) or die "Error adding TXT: $!\n"; $msg->attach( Type => 'application/pdf', Path => $write_path, Filename => $file_name ) or die "Error adding PDF: $!\n"; $mailer->datasend($msg->as_string); $mailer->dataend(); $mailer->quit();


The problem I'm getting, is that it DOES send, but when it comes out my end, the attachments are all screwed:

http://www.tiikoni.com/tis/view/?id=bfa8ee3

(none of them open)

What am I doing wrong?

UPDATE: Mmm, I may have to scrap this method anyway - as the frigging IO::Socket::SSL.pm bug with regards to this line:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1(?:_?[12])?))$}i

...needing to be this line:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))}i

(or else it fails with Gmail)

totally screws up a load of other modules :( Back to the drawing board I guess



TIA

Andy

Replies are listed 'Best First'.
Re: MIME::Lite - weird attachment issue
by noxxi (Pilgrim) on Sep 06, 2015 at 05:59 UTC

    > ... as the frigging IO::Socket::SSL.pm bug

    This is not a bug in IO::Socket::SSL but a failure in Net::SMTP::TLS to properly set SSL_version. Note that the module you use had its last release 9 years ago and is clearly unmaintained. This problem is fixed in Net::SMTP::TLS::ButMaintained (last release two years ago) but I recommend to actually use current releases of Net::SMTP (version 3.x) which have TLS and IPv6 support built in.

    And please, if you think there is an unfixed bug in a module file a bug report instead of unhelpfully complaining about the "frigging" module. The author of the module might actually be willing to help you. In this case the relevant bug report was already filed 2012 and if you would care to read it you would see the problem explained and also described what need to be fixed.

    Steffen Ullrich, maintainer of IO::Socket::SSL

Re: MIME::Lite - weird attachment issue
by Anonymous Monk on Sep 05, 2015 at 10:13 UTC
    What version of io:soc:ssl?

      our $VERSION = '2.019';

      I have managed to find a way around it now, using another module to send them. The MIME::Lite one was causing me too many headaches :(