I'm getting an error when using the Socket SMTP part of this code (not the sendmail part) below on Windows 10 Perl 5.22 with taint mode on.
I would like to get the code working on windows and linux, but the first test on windows gave this error.
Sending Email: Sender address 'valid@email.was.used' not valid. inappropriate i/o control operation
What can be done to get this portable?

sub send_email { my ($self, %email_set) = @_; my ($x, $here, $there, $null) = ('', '', '', ''); # Format input. $email_set{to} =~ s/[ \t]+/, /g; $email_set{from} =~ s/.*<([^\s]*?)>/$1/; $email_set{message} =~ s/^\./\.\./gm; #$email_set{message} =~ s/\r\n/\n/g; #$email_set{message} =~ s/\n/\r\n/g; $cfg{smtp_server} =~ s/\A\s+|\s+\z//g; # Send email via SMTP. if ($cfg{mail_type} == 1) { ($x, $x, $x, $x, $here) = gethostbyname($null); ($x, $x, $x, $x, $there) = gethostbyname($cfg{smtp_server}); my $thisserver = pack('S n a4 x8', 2, 0, $here); my $remoteserver = pack('S n a4 x8', 2, 25, $there); use Carp; croak "Socket failure. $!" if (!(socket(S, 2, 1, 6))); croak "Bind failure. $!" if (!(bind(S, $thisserver))); croak "Connection to $cfg{smtp_server} has failed. $!" if (!(connect(S, $remoteserver))); my $oldfh = select(S); $| = 1; select($oldfh); $_ = <S>; croak "Sending Email: data in Connect error - 220. $!" if ($_ !~ /^220/); print S "HELO $cfg{smtp_server}\r\n"; $_ = <S>; croak "Sending Email: data in Connect error - 250. $!" if ($_ !~ /^250/); print S "MAIL FROM:<$email_set{from}>\n"; $_ = <S>; croak "Sending Email: Sender address '$email_set{from}' not valid. $ +!" if ($_ !~ /^250/); print S "RCPT TO:<$email_set{to}>\n"; $_ = <S>; croak "Sending Email: Recipient address '$email_set{to}' not valid. +$!" if ($_ !~ /^250/); print S "DATA\n"; $_ = <S>; croak "Sending Email: Message send failed - 354. $!" if ($_ !~ /^354/); } # Send email via sendmail. $ENV{PATH} = ''; if ($cfg{mail_type} == 0) { open S, "| $cfg{mail_program} -t" or croak "Mailprogram error. at $! +"; print S <<THE_EMAIL; From: $email_set{from} Subject: $email_set{subject} To: $email_set{to} X-Mailer: Flex-WPS Mail_Module v1.0 Content-type: text/plain $email_set{message} THE_EMAIL } # Send email via SMTP. if ($cfg{mail_type} == 1) { $_ = <S>; croak "Sending Email: Message send failed - try again - 250. $!" if ($_ !~ /^250/); print S "QUIT\n"; } close(S); return 1; }


In reply to Socket SMTP email inappropriate i/o control operation by $h4X4_&#124;=73}{

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.