MIME::Lite 3.030 - NET::SMTP 与 smtps(端口 465) [英] MIME::Lite 3.030 - NET::SMTP with smtps (port 465)

查看:40
本文介绍了MIME::Lite 3.030 - NET::SMTP 与 smtps(端口 465)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MIME::Lite 可以将额外的参数传递给 Net::SMTP 构造函数.
MIME::Lite 3.030 版在其传递的 Net::SMTP 参数列表中不包含 SSL.

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.

是否可以在修改MIME::Lite源代码的情况下改变它?

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: $!
";

推荐答案

你可以做的一件事是用一些修改传递给它的参数的函数包装 __opts.

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

在第 2876 行:

my %opts = __opts(\%args, @_net_smtp_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;
};

这样每次对 MIME::Lite::__opts 的调用都会被拦截",您可以随意修改参数.

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

这篇关于MIME::Lite 3.030 - NET::SMTP 与 smtps(端口 465)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆