- die unless $self->{smtp};
-
- $self->{smtp}->starttls(SSL_verify_mode => 0) || die if $self->{security} eq 'tls';
-
- return 1 unless $cfg->{login};
-
- $self->{smtp}->auth($cfg->{user}, $cfg->{password}) or die;
+ if (!$self->{smtp}) {
+ $self->extended_status('SMTP connection could not be initialized');
+ die $self->extended_status;
+ }
+
+ if ($self->{security} eq 'tls') {
+ $self->{smtp}->starttls(SSL_verify_mode => 0) or do {
+ $self->extended_status("$@");
+ die $self->extended_status;
+ };
+ }
+
+ # Backwards compatibility: older Versions used 'user' instead of the
+ # intended 'login'. Support both.
+ my $login = $cfg->{login} || $cfg->{user};
+
+ return 1 unless $login;
+
+ if (!$self->{smtp}->auth($login, $cfg->{password})) {
+ $self->extended_status('SMTP authentication failed');
+ die $self->extended_status;
+ }