in reply to Net::SMTP error

Obviously you failed to connect to the server in those bad cases.

It is always a better practice to check return code on eah step. You cannot expect that the connection works all the time, but you should expect your code to handle exceptional situations.

BTW, better specify timeout when you create SMTP:

$smtp = Net::SMTP->new('mailhost', Timeout => 60);