MIME::Lite 3.030 - NET::SMTP with smtps (port 465)

匿名 (未验证) 提交于 2019-12-03 08:30:34

问题:

MIME::Lite can pass extra parameters to Net::SMTP constructor.
Version MIME::Lite 3.030 does not include SSL on its list of passed Net::SMTP parameters.

Is it possible to change it without modifying MIME::Lite source code?

   1 package MIME::Lite;      ...  355 $VERSION = '3.030';      ... 2843 my @_net_smtp_opts = qw( Hello LocalAddr LocalPort Timeout 2844                          Port ExactAddresses Debug );      .... 2847 sub __opts { 2848     my $args=shift; 2849     return map { exists $args->{$_} ? ( $_ => $args->{$_} ) : () } @_; 2850 }      .... 2852 sub send_by_smtp {          .... 2876     my %opts = __opts(\%args, @_net_smtp_opts); 2877     my $smtp = MIME::Lite::SMTP->new( $hostname, %opts ) 2878       or Carp::croak "SMTP Failed to connect to mail server: $!\n"; 

回答1:

One thing you could do is wrapping __opts with some function that modifies the parameters are passed to it.

In line 2876:

my %opts = __opts(\%args, @_net_smtp_opts); 

The advantage here is that after the reference to %args, the rest of parameters is always the array @net_smtp_opts defined earlier. Unfortunately you can't modify its value at distance (it's a lexical variable), but you can do something like this:

use strict; use warnings;  use MIME::Lite; use Class::Method::Modifiers;  around 'MIME::Lite::__opts' => sub {   my $orig = shift;   push(@_,'SSL') if @_ >= 2 && $_[1] eq 'Hello';   my (@ret) = $orig->(@_);   return @ret; }; 

This way every call to MIME::Lite::__opts is "intercepted", and you have the ability to modify the parameters at your will.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!