Reputation: 839
SO.
I'm failing at sending mail from my Perl script. This is what my code looks like:
use Net::SMTP;
$smtp = Net::SMTP->new("smtpserver.mydomain.com");
$smtp->mail("myemail\@mydomain.com");
$smtp->to("myemail\@mydomain.com");
$smtp->data();
$smtp->datasend("From: myemail\@mydomain.com\n");
$smtp->datasend("To: myemail\@mydomain.com\n");
$smtp->datasend("Subject: Test message\n");
$smtp->datasend("Just a test message.\n");
$smtp->dataend();
$smtp->quit;
This is what the debug option throws:
Net::SMTP>>> Net::SMTP(2.31)
Net::SMTP>>> Net::Cmd(2.29)
Net::SMTP>>> Exporter(5.64_03)
Net::SMTP>>> IO::Socket::INET(1.31)
Net::SMTP>>> IO::Socket(1.32)
Net::SMTP>>> IO::Handle(1.31)
Net::SMTP=GLOB(0x1d1a06c)<<< 220 ESMTP Postfix
Net::SMTP=GLOB(0x1d1a06c)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x1d1a06c)<<< 250-
Net::SMTP=GLOB(0x1d1a06c)<<< 250-PIPELINING
Net::SMTP=GLOB(0x1d1a06c)<<< 250-SIZE
Net::SMTP=GLOB(0x1d1a06c)<<< 250-ETRN
Net::SMTP=GLOB(0x1d1a06c)<<< 250-STARTTLS
Net::SMTP=GLOB(0x1d1a06c)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x1d1a06c)<<< 250-8BITMIME
Net::SMTP=GLOB(0x1d1a06c)<<< 250 DSN
Net::SMTP=GLOB(0x1d1a06c)>>> MAIL FROM:<[email protected]>
Net::SMTP=GLOB(0x1d1a06c)<<< 250 2.1.0 Ok
Net::SMTP=GLOB(0x1d1a06c)>>> RCPT TO:<[email protected]>
Net::SMTP=GLOB(0x1d1a06c)<<< 450 4.7.1 <localhost.localdomain>: Helo command rejected: Service temporarily unavailable
Net::SMTP=GLOB(0x1d1a06c)>>> DATA
Net::SMTP=GLOB(0x1d1a06c)<<< 554 5.5.1 Error: no valid recipients
Net::SMTP=GLOB(0x1d1a06c)>>> From: [email protected]
Net::SMTP=GLOB(0x1d1a06c)>>> To: [email protected]
Net::SMTP=GLOB(0x1d1a06c)>>> Subject: Test message
Net::SMTP=GLOB(0x1d1a06c)>>> Just a test message.
Net::SMTP=GLOB(0x1d1a06c)>>> .
Net::SMTP=GLOB(0x1d1a06c)<<< 221 2.7.0 Error: I can break rules, too. Goodbye.
Net::SMTP=GLOB(0x1d1a06c)>>> QUIT
The interesting part is that the SMTP server replies with 250 OK when I talk directly to it and I receive the mail just fine:
220 ESMTP Postfix
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Just a test message.
.
250 2.0.0 Ok: queued as B68672C02B
Does someone have some light to shed?
Thanks in advance.
Upvotes: 1
Views: 1650
Reputation: 10913
The SMTP server (postfix) "does not like" hostname used in EHLO
command but rejects it in reply to RCPT TO:
command.
>>> MAIL FROM:<[email protected]>
<<< 250 2.1.0 Ok
....
>>> RCPT TO:<[email protected]>
<<< 450 4.7.1 <localhost.localdomain>: Helo command rejected: Service temporarily unavailable
You can make Net::SMTP use another hostname in HELO
/EHLO
command by passing Hello
parameter to new
.
$smtp = Net::SMTP->new('smtpserver.mydomain.com', Hello => 'host.example.net');
Upvotes: 1
Reputation: 194
Just posting this as an answer instead so that it can be accepted as the answer, as requested by triplee.
Something might be wrong in your domain setup.
also add $smtp->datasend("\n"); underneath $smtp->datasend("Subject: Test message\n"); in a new line, else it will not show mesage text.
like this.
$smtp->datasend("Subject: Test message\n");
$smtp->datasend("\n");
$smtp->datasend("Just a test message.\n");
Upvotes: 2