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

Hi i am trying to write an email with my gmx mail account. It requires STARTTLS or TLS. I need to find out some things before i can do this but i first have a question about the difference between the modules Net::SMTP and Net::SMTPS, because it looks like both can do the job. The modules came automattically with my download of strawberry perl. Could someone tell me the difference between them? I have already tried to use the module Net::SMTP::TLS but i got an error on the SSL version and i have heard that it is an outdated module. Any advice is welcome. Ty.

Replies are listed 'Best First'.
Re: send mail with STARTTLS
by atcroft (Abbot) on Dec 15, 2025 at 09:06 UTC

    From Net::SMTP:

    DESCRIPTION

    This module implements a client interface to the SMTP and ESMTP protocol, enabling a perl5 application to talk to SMTP servers. This documentation assumes that you are familiar with the concepts of the SMTP protocol described in RFC2821. With IO::Socket::SSL installed it also provides support for implicit and explicit TLS encryption, i.e. SMTPS or SMTP+STARTTLS.

    The Net::SMTP class is a subclass of Net::Cmd and (depending on avaibility) of IO::Socket::IP, IO::Socket::INET6 or IO::Socket::INET.

    From Net::SMTP::TLS:

    DESCRIPTION

    Net::SMTP::TLS is a TLS and AUTH capable SMTP client which offers an interface that users will find familiar from Net::SMTP. Net::SMTP::TLS implements a subset of the methods provided by that module, but certainly not (yet) a complete mirror image of that API.

    The methods supported by Net::SMTP::TLS are used in the above example. Though self explanatory for the most part, please see the perldoc for Net::SMTP if you are unclear.

    From Net::SMTPS:

    DESCRIPTION

    This module implements a wrapper for Net::SMTP, enabling over-SSL/STARTTLS support. This module inherits most of all the methods from Net::SMTP(2.X). You may use all the friendly options that came bundled with Net::SMTP. You can control the SSL usage with the options of new() constructor method. 'doSSL' option is the switch, and, If you would like to control detailed SSL settings, you can set SSL_* options that are brought from IO::Socket::SSL. Please see the document of IO::Socket::SSL about these options detail.

    Just one method difference from the Net::SMTP, you can select SMTP AUTH mechanism as the third option of auth() method.

    As of Version 3.10 of Net::SMTP(libnet) includes SSL/STARTTLS capabilities, so this wrapper module's significance disappareing.

    Net::SMTP is the older module with numerous options; Net::SMTP::TLS and Net::SMTPS are newer modules with less options that tried to simplify the process to some degree (but do not match all the functionality of Net::SMTP as a result). All three appear to use IO::Socket::SSL under the hood to provide TLS encryption (SMTPS or SMTP+STARTTLS).

    Hope that helps.

Re: send mail with STARTTLS
by hippo (Archbishop) on Dec 15, 2025 at 09:41 UTC
    i first have a question about the difference between the modules Net::SMTP and Net::SMTPS, because it looks like both can do the job.

    Yes, both can do the job now. This was not always the case - Net::SMTPS exists because Net::SMTP never used to have any TLS support. Since it does now you should be able to use either. I tend to stick with Net::SMTPS purely out of habit.

    This is covered in the DESCRIPTION of Net::SMTPS as quoted verbatim by brother atcroft in his reply.


    🦛

Re: send mail with STARTTLS
by Anonymous Monk on Dec 15, 2025 at 11:49 UTC

    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.

      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.