in reply to send mail with STARTTLS

Ty for responding. I decided to work with the NET::SMTP module, but i am having a problem. I managed to connect to my mailserver, give the starttls command and give the necessary info to send the mail. I am using the debug option so that i can see the socket communication. Everything is looking ok until the very end then it fails. I have included the source file and the output. I have made some changes to protect my privacy. code:

use strict; use warnings; use Net::SMTP ; my $afz = 'anyone@gmx.com'; my $pass = 'somepass'; my $ontv = 'any@gmail.com'; my $mailer = Net::SMTP->new( 'mail.gmx.com', Hello => 'mail.gmx.com', Port => 587, Debug => 1 ); $mailer->starttls(); $mailer->auth($afz, $pass); $mailer->mail($afz); $mailer->recipient($ontv); $mailer->data(); $mailer->datasend("From: $afz"); $mailer->datasend("To: $ontv"); $mailer->datasend("Subject: testmail"); $mailer->datasend("\n"); $mailer->datasend("Hallo daar."); $mailer->dataend(); $mailer->quit

here is the output:

C:\Strawberry\scripts>smtp.pl Net::SMTP>>> Net::SMTP(3.15) Net::SMTP>>> Net::Cmd(3.15) Net::SMTP>>> Exporter(5.79) Net::SMTP>>> IO::Socket::IP(0.43) Net::SMTP>>> IO::Socket(1.55) Net::SMTP>>> IO::Handle(1.55) Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 220 gmx.net (mrgmx004) Nemesis ESMTP +Service ready Net::SMTP=GLOB(0x1d5ecdf64b8)>>> EHLO mail.gmx.com Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 250-gmx.net Hello mail.gmx.com [128.8 +5.234.120] Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 250-8BITMIME Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 250-SIZE 141557760 Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 250 STARTTLS Net::SMTP=GLOB(0x1d5ecdf64b8)>>> STARTTLS Net::SMTP=GLOB(0x1d5ecdf64b8)<<< 220 OK Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> EHLO mail.gmx.com Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250-gmx.net Hello mail.gmx.com +[128.85.234.120] Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250-8BITMIME Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250-AUTH PLAIN LOGIN Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250 SIZE 141557760 Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> AUTH PLAIN YW5keWFuZW1whYXRAerZ +214LmNvbQBhbmR5YW5lbWFhdEBnbXguY29tAGtpZGRvMm1hbg== Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 235 Authentication succeeded Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> MAIL FROM:<anyone@gmx.com> Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250 Requested mail action okay, + completed Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> RCPT TO:<any@gmail.com> Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 250 OK Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> DATA Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 354 Start mail input; end with +<CRLF>.<CRLF> Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> From: anyone@gmx.com Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> To: any@gmail.com Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> Subject: testmail Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> Hallo daar. Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> . Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 554-Transaction failed Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 554-Reject due to policy restri +ctions. Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 554 For explanation visit https +://postmaster.gmx.net/en/case?c=hi&i=ip&v=178.85.237.120&r=1M4s4r-1vT +ArD3yPX-00BYlG Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)>>> QUIT Net::SMTP::_SSL=GLOB(0x1d5ecdf64b8)<<< 221 gmx.net Service closing tra +nsmission channel

I have visited the gmx website mentioned to see what the problem is and it says:

554 Nemesis ESMTP Service not available Transaction failed Reject due to policy restrictions Please note that, if your email header is not RFC 5321 and RFC 5322 compliant, your message will be rejected by our system.

This includes the following:

The following email headers included in your message must be syntactically correct: Date, From, Sender, To

The following headers included in your email must be limited to just one each: BCC, CC, Date, From, Sender, Subject, To

Therefore, we would advise you to check that the above mentioned information provided by your system is correct. Should you need additional support, please contact your System Administrator.

Could someone help me further? I really don't know what to do. I also tried to work with incoming mail and this is working fine so everything seems ok.Ty in advance.

Replies are listed 'Best First'.
Re^2: send mail with STARTTLS
by Corion (Patriarch) on Dec 15, 2025 at 13:07 UTC

    You are not sending a Date header at all in your code, but it seems gmx wants one.

      I tried this:

      use strict; use warnings; use Net::SMTP ; my $afz = 'anyone@gmx.com'; my $pass = '*****'; my $ontv = 'any@gmail.com'; my $date = localtime(); my $mailer = Net::SMTP->new( 'mail.gmx.com', Hello => 'mail.gmx.com', Port => 587, Debug => 1 ); $mailer->starttls(); $mailer->auth($afz, $pass); $mailer->mail($afz); $mailer->recipient($ontv); $mailer->data(); $mailer->datasend("From: $afz"); $mailer->datasend("To: $ontv"); $mailer->datasend("Subject: testmail"); $mailer->datasend("Date: $date"); $mailer->datasend("\n"); $mailer->datasend("Hallo daar."); $mailer->dataend(); $mailer->quit
      But it does not change anything. I also tried giving just the date and not the time but nothing. Maybe i'll try sending from my gmail account to my gmx account but that is a pour solution if it works at all.

        Try with newlines at the end of each datasend that doesn't have and end with a dataend call, not a dot? That's what the module example shows.

        Are you sure that [func://localtime]() or giving "just the date" are things that will supply a well-formatted Date header?

        You most likely want something like DateTime::Format::Mail. At least your value should look something like Sat, 29 Mar 2003 22:11:18 -0800.

        use Time::Piece; my $date = localtime (time)->strftime ('%a, %d %b %Y %T %z');

        works for me. YMMV.


        🦛