in reply to Re^2: send mail with STARTTLS
in thread send mail with STARTTLS

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.

Replies are listed 'Best First'.
Re^4: send mail with STARTTLS
by ysth (Canon) on Dec 15, 2025 at 15:27 UTC
    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.

      Yes now it is working, thank you very much. Sorry for not paying attention, I found an example on the internet but it wasn't correct. The module documentation is correct indeed and everything is working just fine now.

Re^4: send mail with STARTTLS
by Corion (Patriarch) on Dec 15, 2025 at 13:54 UTC

    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.

      As a funny sidenote, depending on the Date library used, just make sure the weekday name calculation is correct. Many, many, many years ago i once ran into that exact problem. Sudenly, my mails started getting rejected by some server, leading me on a long bug hunt... until i found a leap year bug that messed up weekday names...

      PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
      Also check out my sisters artwork and my weekly webcomics
        [...]mails started getting rejected by some server [...] until i found a leap year bug that messed up weekday names [...]

        Now that's a cool bug. I never expected servers to actually validate weekdays. Checking for one of the seven weekday names at the right position, yes, of course. But not actually matching the name to the date. On the other hand, there might have been some lazy spammers that simply always sent "Monday" or something like that.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^4: send mail with STARTTLS
by hippo (Archbishop) on Dec 15, 2025 at 14:27 UTC
    use Time::Piece; my $date = localtime (time)->strftime ('%a, %d %b %Y %T %z');

    works for me. YMMV.


    🦛