Thanks to brian_d_foy, we've got the final solution: a patch to Net::SMTP. Hopefully this will be applied to CPAN in the next few days. Using this patch, you no longer have to declare a LocalPort or LocalAddr. Instead you set 'Reuse => 1'.

$objst->send( 'SMTP', ssl => 1, Host => $RemoteHost, Port => $RemotePort, Proto => 'tcp', username => $username, password => $password, Debug => 1, Reuse => 1, );

Here's the patch:

# Patch to Net::SMTP BEGIN { use Net::SMTP; no warnings 'redefine'; *Net::SMTP::new = sub { print "In my Net::SMTP::new...\n"; package Net::SMTP; use Net::Config; use Net::Cmd; my $self = shift; my $type = ref($self) || $self; my ($host,%arg); if (@_ % 2) { $host = shift ; %arg = @_; } else { %arg = @_; $host=delete $arg{Host}; } my $hosts = defined $host ? $host : $NetConfig{smtp_hosts}; my $obj; my $h; foreach $h (@{ref($hosts) ? $hosts : [ $hosts ]}) { $obj = $type->SUPER::new(PeerAddr => ($host = $h), PeerPort => $arg{Port} || 'smtp(25)', $arg{LocalAddr} ? ( LocalAddr => $arg{LocalAddr} ) : ( +), $arg{LocalPort} ? ( LocalPort => $arg{LocalPort} ) : ( +), Proto => 'tcp', Timeout => defined $arg{Timeout} ? $arg{Timeout} : 120 ); last if $obj; } return undef unless defined $obj; $obj->autoflush(1); $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef); unless ($obj->response() == CMD_OK) { $obj->close(); return undef; } ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses}; ${*$obj}{'ne +t_smtp_host'} = $host; (${*$obj}{'net_smtp_banner'}) = $obj->message; (${*$obj}{'net_smtp_domain'}) = $obj->message =~ /\A\s*(\S+)/; unless($obj->hello($arg{Hello} || "")) { $obj->close(); return undef; } $obj; } }

In reply to Re^2: Using Email::Stuff to send SMTP mail through GMail by initself
in thread Using Email::Stuff to send SMTP mail through GMail by initself

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.