Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to send a mail from my gmx account, using Net::SMTP module. I have debug on so i can follow the data traffic. The login seems okay and up to the end everything looks good, but right before the end it fails saying:554-Transaction failed Net::SMTP::_SSL=GLOB(0x1844d3c)<<< 554 Unauthorized sender address. I cannot understand what is the problem because the sender's address is mine and i just logged in successfully. Here is my script:

use strict; use warnings; use Net::SMTP; my $smtp = Net::SMTP->new('mail.gmx.com', Hello => 'Rob.nl', Timeout => 30, Debug => 1, SSL => 1, Port => 465 ); $smtp->auth('accountname@gmx.com','password'); $smtp->mail('accountname@gmx.com'); $smtp->to('someone@gmail.com'); $smtp->data; $smtp->datasend("Hi."); $smtp->dataend; $smtp->quit;

I hope someone can help, tx.

Replies are listed 'Best First'.
Re: problem sending mail
by dave_the_m (Monsignor) on Aug 05, 2020 at 15:11 UTC
    You're not checking the return value of $smtp->auth() - are you sure it's succeeding?

    Dave.

Re: problem sending mail
by jeffenstein (Hermit) on Aug 06, 2020 at 00:32 UTC

    A wild guess would be that your provider is also checking the address in the header, and not just the envelope. However, you are not adding a header, so it considers this empty value as invalid.

    Try adding a header in the message and see if that works.

    Even better would be to use one of the modules mentioned by the other monks, where someone has already implemented the various standards for you.

Re: problem sending mail
by soonix (Chancellor) on Aug 05, 2020 at 19:03 UTC
    policy of your email provider, see also https://stackoverflow.com/a/58573839 (not a Perl problem)

    perhaps they check only part of the username, and you use the wrong TLD (gmx.net/gmx.com/gmx.whatever), or maybe it's not exactly the same address, because of a typo or an invisible-and/or-unicode character

      With powershell i can send a mail. on port 587, using SSL, like so:

      $from = "any@gmx.com" $to = "rob@gmail.com" $subj = "test PShell." $body = "boddy" $server = "mail.gmx.com" $port = "587" Send-MailMessage -From $from -To $to -Subject $subj -body $body -SmtpS +erver $server -Port $port -UseSsl -Credential (Get-Credential)

      Surely i can do the same with Perl!

        Surely i can do the same with Perl!

        Certainly, and the fact that you're having trouble doing so means there is some difference between the command that works and the one that doesn't, so you'll have to figure out what the differences between the two are. (Consider comparing a successful transaction and an unsuccessful one with Wireshark.)

        on port 587, using SSL

        Well, that's at least one difference between the code in the root node.

        You might want to give the more modern Email::* modules by RJBS a try, for example see Email::Sender::Manual::QuickStart.

Re: problem sending mail
by Anonymous Monk on Aug 06, 2020 at 01:09 UTC

    Yes, I added a header with a From field and it is allright now, thank you.

Re: problem sending mail
by Anonymous Monk on Aug 05, 2020 at 15:44 UTC

    Here is the entire output, login looks fine.

    Net::SMTP::_SSL>>> Net::SMTP::_SSL Net::SMTP::_SSL>>> IO::Socket::SSL(2.040) Net::SMTP::_SSL>>> IO::Socket::IP(0.38) Net::SMTP::_SSL>>> IO::Socket(1.38) Net::SMTP::_SSL>>> IO::Handle(1.36) Net::SMTP::_SSL>>> Exporter(5.72) Net::SMTP::_SSL>>> Net::SMTP(3.10) Net::SMTP::_SSL>>> Net::Cmd(3.10) Net::SMTP::_SSL=GLOB(0x1875d54)<<< 220 gmx.com (mrgmx105) Nemesis ESMT +P Service ready Net::SMTP::_SSL=GLOB(0x1875d54)>>> EHLO Rob.nl Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250-gmx.com Hello Rob.nl [83.82.13. +137] Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250-8BITMIME Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250-AUTH LOGIN PLAIN Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250 SIZE 69920427 Net::SMTP::_SSL=GLOB(0x1875d54)>>> AUTH LOGIN Net::SMTP::_SSL=GLOB(0x1875d54)<<< 334 VXNlcsm5hbWU6 Net::SMTP::_SSL=GLOB(0x1875d54)<<< (decoded) Username: Net::SMTP::_SSL=GLOB(0x1875d54)>>> (decoded) someone@example.com Net::SMTP::_SSL=GLOB(0x1875d54)>>> <redacted> Net::SMTP::_SSL=GLOB(0x1875d54)<<< 334 <redacted> Net::SMTP::_SSL=GLOB(0x1875d54)<<< (decoded) Password: Net::SMTP::_SSL=GLOB(0x1875d54)>>> (decoded) <redacted> Net::SMTP::_SSL=GLOB(0x1875d54)>>> <redacted> Net::SMTP::_SSL=GLOB(0x1875d54)<<< 235 Authentication succeeded Net::SMTP::_SSL=GLOB(0x1875d54)>>> MAIL FROM:<someone@example.com> Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250 Requested mail action okay, com +pleted Net::SMTP::_SSL=GLOB(0x1875d54)>>> RCPT TO:<anyone@example.com> Net::SMTP::_SSL=GLOB(0x1875d54)<<< 250 OK Net::SMTP::_SSL=GLOB(0x1875d54)>>> DATA Net::SMTP::_SSL=GLOB(0x1875d54)<<< 354 Start mail input; end with <CRL +F>.<CRLF> Net::SMTP::_SSL=GLOB(0x1875d54)>>> Hi amdy Net::SMTP::_SSL=GLOB(0x1875d54)>>> . Net::SMTP::_SSL=GLOB(0x1875d54)<<< 554-Transaction failed Net::SMTP::_SSL=GLOB(0x1875d54)<<< 554 Unauthorized sender address. Net::SMTP::_SSL=GLOB(0x1875d54)>>> QUIT Net::SMTP::_SSL=GLOB(0x1875d54)<<< 221 gmx.com Service closing transmi +ssion channel

      If that was your actual password, you really need to change it posthaste. Assume the evildoers have seen it, even if the site operators here remove it.