Telnet SMTP send mail timeout - email

I want to use telnet to send an e-mail with SMTP. It seemed that I had connect to the mail service successfully. And the message had been put in the queue too. But why did the SMTP service failed to send the message to the received address?
When I searched the solution by the internet, someone had said that firewall should paid it. But I have no idea about the relationship between the firewall or antivirus software and telnet.
This is my command:
220 smtp-5-124.smtpsmail.fmail.xd.sinanode.com ESMTP
helo a
250 smtp-5-124.smtpsmail.fmail.xd.sinanode.com
auth login
334 VXNlcd5hbWU6
a25vd215aGV2341241fasYS5jbg==
334 UGFzczdvcmQ6
UmF5V2adfa23adsfZzgyNA==
235 OK Authenticated
mail from: <knowmyheart#sina.cn>
502 unimplemented (#5.5.1)
mail from:<knowmyheart#sina.cn>
553 Envolope sender mismatch with login user..
mail from:<knowmyheart#sina.cn>
250 ok
rcpt to:<517447201#qq.com>
250 ok
data
354 End data with <CR><LF>.<CR><LF>
subject: test
to:<517447201#qq.com>
from:<knowmyheart#sina.cn>
Testttttttttttttt!
.
250 ok queue id 6744281442287
451 Timeout.
By the way, I tried it both on Windows 10 and Ubuntu-15.10. And both of them failed with the same question.

Finally, I found where I was wrong.
In my previous case,I failed to send a e-mail with the above code.I had succeeded in connecting with the SMTP server, and everything worked except the "Timeout" response. Actually, the "Timeout" didn't mean I failed to send a e-mail but lose the TCP connection. Hours Later, I login my e-mail, which was used for sending, finding that I receive a mail. The mail told me the e-mail I sent hours before with telnet was given back, failing to post. So it meant that the reason was hardly because of my telnet client, but in server or something else.
Finally, I found that it was because of my mail format. In my previous code, after I sending keyword -- "data", I immediately send the content.
data
354 End data with <CR><LF>.<CR><LF>
subject: test
to:<517447201#qq.com>
from:<knowmyheart#sina.cn>
Testttttttttttttt!
.
250 ok queue id 6744281442287
When I changed it to this, it worked.
data
354 End data with <CR><LF>.<CR><LF>
subject: test
to:<517447201#qq.com>
from:<knowmyheart#sina.cn>
Testttttttttttttt!
.
250 ok queue id 6744281442287
Notice that the difference between the codes is the empty line before the content in this mail. "subject", "to" and "from" are the headers. Between the header and the content, there must be an empty line.
Similarly, the headers in mail can be ignored. The code is like this:
data
354 End data with <CR><LF>.<CR><LF>
Testttttttttttttt!
.
250 ok queue id 6744281442287
451 Timeout.
Even if there is a "Timeout", it affect nothing but break the tcp connection between localhost and smtp server.

Related

postfix header_checks fails for no reason with ! (not operator)

Why does regular expression ! doesn't work?
In my header_checks file I got
!/^Subject:.*NotBot.*/ REJECT fuck off
In my master.cf I use the cleanup daemon for checking
cleanup unix n - n - 0 cleanup
-o header_checks=pcre:/etc/postfix/header_checks
when I connect to stmpd via telnet to test (Good Subject) I get this
220 test.com ESMTP Postfix
HELO www.test.com
MAIL From: <test#test.com>
RCPT To: <test#test.com>
DATA
From: <tester#hahaha.com>
Subject: NotBot123
test250 test.com
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
.
550 5.7.1 fuck off
But Bad Subject's also work
220 example.com ESMTP Postfix
HELO www.example.com
MAIL From: <test#test.com>
RCPT To: <test#test.com>
DATA
From: <tester#hahaha.com>
Subject: hahaha
test250 test.com
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
.
550 5.7.1 fuck off
Fixed it! was pretty easy..
the check_headers is checked for every information in the mail.. so you need to use if/endif to check only Subject: field.
if /^Subject:/
!/^Subject:.*NotBot.*/ REJECT fuck off
endif
Dumb spammers suspended my email account due to abusing my open stmp port.

exim Timing Out to Gmail

I have a Centos server with exim installed. I am trying to send en email from the command line like this:
exim -v account#gmail.com
From: email#mydomain.com
To: account#gmail.com
Subject: test email
this is a test
^D
I have also tried:
echo 'test message' | mail -s Test1 account#gmail.com
as well as sending from a PHP script.
The result is the email times out. The logs indicate exim is timing out:
H=alt2.gmail-smtp-in.l.google.com [173.194.219.26] Connection timed out
I believe iptables are correct. I have scanned the server from an external IP and ports 25, 265 and 587 are open. (Not sure 587 needs to be since this will be a send-only situation most likely.)
I have also telnet'd to port 25 successfully. (Most of the successful resolutions I have found involved port 25 being blocked. I don't think that is the case here. I have also called my provider and checked. They claim port 25 connections are not blocked.)
I would appreciate some ideas.
Thank you.

Connecting to Gmail SMTP via socket returns different responses per server

I am trying to understand why opening a socket to Gmail's server via SSL provides different responses for different servers. This is stopping me from connecting to Gmail for sending out emails.
Below is a very simple script:
<?php
$smtp_connect = fsockopen('ssl://smtp.googlemail.com', 465,
$errno,
$errstr,
300);
var_dump(fgets($smtp_connect, 512));
?>
On server 1 [no ssl cert installed], the output of the above code is: string(57) "220 smtp.googlemail.com ESMTP s89sm726209qkl.44 - gsmtp
"
On server 2 [ssl cert installed], the output of the above code is: string(71) "220-mycompany.pro.com ESMTP Exim 4.87 #1 Wed, 26 Oct 2016 07:42:49 -0400
"
Can anyone explain why this happens, and how can I make server 2 have the same behavior as server 1?
Update: I have also tried smtp.gmail.com, the output is same as using smtp.googlemail.com.
The line you get the the SMTP welcome message. It is perfectly normal that different servers give a different welcome message. It is even normal that the response to commands you send is different. This means that when communicating with an SMTP server you should not assume fixed strings as response but implement proper parsing of SMTP. See the SMTP standard (RFC 2821) for details about this protocol.

How to output detail message about 5.x.x error on Sendmail

I'm using Sendmail Version 8.14.4 on Centos 6.3.
sendmail.cf of the Sendmail is left default of CentOS.
Sendmail does not output detail response message like below.
Aug 8 21:44:44 localhost sendmail[5075]: u78CicQr005073: to=hogehoge#grandeur09.com, delay=00:00:02, xdelay=00:00:02, mailer=esmtp, pri=120005, relay=mail.grandeur09.com. [124.24.34.228], dsn=5.1.1, stat=User unknown
On the other hand, Postfix can output detail response like below.
Aug 8 21:43:40 localhost postfix/smtp[4993]: EA843120806: to=<hogehoge#grandeur09.com>, relay=mail.grandeur09.com[124.24.34.228]:25, delay=0.32, delays=0.01/0.01/0.28/0.01, dsn=5.1.1, status=bounced (host mail.grandeur09.com[124.24.34.228] said: 550 5.1.1 <hogehoge#grandeur09.com>: Recipient address rejected: User unknown in local recipient table (in reply to RCPT TO command))
The below message is important for me.
User unknown in local recipient table (in reply to RCPT TO command))
Do you know how to output detail response message returned by downstream SMTP server?
I tried to raise log level, but it was useless.

Bugzilla - Email not working

I have installed Bugzilla-4.4 in my new Ubuntu Machine. When I submit a new bug, I got the email sent notification. But the sent email is not received by the recipients . I am using Sendmail mail configuration in Bugzilla. I have also tested "Test" mail configuration in which the mail is logged in bugzilla-4.4/data/mailer.testfile successfully. When I check my mail.log file I found the following:
(1001/1001), delay=3+15:58:59, xdelay=00:00:00, mailer=esmtp, pri=47643784, relay=mailrelay.netcon.in., dsn=4.0.0, stat=Deferred: Connection timed out with mailrelay.netcon.in.
I have no idea what to do.Is anything I missed out while Sendmail configuration? Any help!!
Try nc from command line:
nc mailrelay.netcon.in 25
which should result in something like:
220 mailrelay.netcon.in ESMTP Postfix
If not check for internet connection and/or router firewall rules.