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

i do not understand this: # hack MIME::Lite to support TLS Authentication *MIME::Lite::send_by_smtp_tls = sub { ... please could someone tell me how I cange my perl to worl with TLS
#!/usr/bin/perl # # -------------------------------------------------------------------- +-- # # # Purpose: Email attachments in Perl # # -------------------------------------------------------------------- +-- use MIME::Lite; use Net::SMTP; .... .... ### Create the multipart container $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $message_body ) or die "Error adding the text message part: $!\n"; ### Add the ZIP file $msg->attach ( Type => 'application/zip', Path => $my_file_zip, Filename => $your_file_zip, Disposition => 'attachment' ) or die "Error adding $file_zip: $!\n"; ### Send the Message MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send;
Regards, Milan

Replies are listed 'Best First'.
Re: Using MIME::Lite with TLS
by Corion (Patriarch) on Oct 14, 2009 at 07:55 UTC

    The code

    *MIME::Lite::send_by_smtp_tls = sub { ... }

    installs the subroutine send_by_smtp_tls into MIME::Lite. I guess that it is all you need to later call

    $mail->send_by_smtp_tls();

    But as you left out the important part of it all, the code for send_by_smtp_tls, I don't know. Maybe the usage is

    MIME::Lite->send('smtp_tls', $mail_host, Timeout=>60); $msg->send;

    instead.

Re: Using MIME::Lite with TLS
by jethro (Monsignor) on Oct 14, 2009 at 10:38 UTC

    It seems you have found something like Using MIME::Lite with TLS or the gmail.pm that is linked to in that thread.

    Without looking at it in detail I would guess that you might copy the method referenced there and the following two lines into your own code. This would overload/overwrite/substitute the corresponding method in Mime::Lite similar to what you would do if you subclassed Mime::Lite and defined the method in that subclass

    You also need to install any modules needed by that method and it might work.

Re: Using MIME::Lite with TLS
by spx2 (Deacon) on Oct 14, 2009 at 10:38 UTC
    Yeah, that's pretty common I guess(maybe you can patch it for MIME::Lite's author and send him a patch). I've also used monkeypatching in my module also Backup::Email::Send, I guess it's a pretty common technique.