The else doesn't need to be there. The $smtp is still going to need to be created in the same way (or at least it seems so to me). The authentication action occurs after the Net::SMTP object has been created, which was part of my initial concern when adding support to MIME::Lite. I am still working through why Net::SMTP doesn't allow for the authentication arguments in the object creation. It would seem that Net::SMTP should perhaps be the one that bends and allows for the authenication to be passed into it on object creation.
If we moved this logic into the Net::SMTP module, what would happen if we did this right before we return the Net::STMP object:
if (defined $arg{User}) {
$obj->auth($arg{User},$arg{Password});
}
inside of the Net::SMTP
new?
Then when we create a new Net::SMTP call we do it as:
MIME::Lite->send('smtp', $out_smtp ,
Port =>$smtp_port ,
Timeout=>60 ,
Debug => $debug ,
Hello => 'domain.com',
User => 'trs80',
Password => 'blah' );
My simple test indicates that it works, but I need to carefully review the side effects of performing the auth in the object creation.
Placing the change inside of Net::SMTP makes more sense in that it keeps the logic in the right problem space and thereby making it benefical to a larger user base.