Should I see email on port 25 with netcat? - linux

Assuming I have a domain forwarded properly to a box (i.e., I can see a webpage on the box from the outside world) If I use netcat to listen on some ports from a ssh session:
nc -l 587
nc -l 25
and send mail to the server user#mydomain.com
I should see the beginning of the handshake in the send attempts? I know my ISP does not block port 25 because I can see a browser header with netcat if I go to http://mydomain.com:25

Tons of things could be going wrong:
1) SMTP requires the server talk first, so the email sender is probably waiting for your server to say something.
2) If you're not running a valid mail server, email senders may mark your host as unresponsive and backoff for several hours before retrying.
3) If you just changed your DNS, it may take hours/days for that to propagate. (Not everyone respects TTL, especially low ones.)
4) Some servers are configured to drop mail if the source or destination SPF isn't set up properly. (To encourage everyone to use SPF.) Try adding a SPF record. (And make sure your MX record is correct.)

Related

Mail of PHP, DNS request timed out, and FQDN

I want to make mail() of PHP work in my Windows Server 2012 R2. To this end, I first installed SMTP by following this page.
One thing that confuses me is the Full-qualified domain name. WIN-RFELH8GM0KN is what it proposes by default. My server hosts several websites, does anyone know which website I should specify here?
I did not change this, as a consequence, mail www.google.com in nslookup returns DNS request timed out. So is it an error?
Of cause, my test.php does not send the mail:
<?php
mail('mymail#gmail.com', 'title', 'content');
?>
Could anyone help?
Update 1 Following the answer of #LittleAI , I started SMTP, but DNS request timed out is still there:
Update 2 Here is php.ini:
telnet localhost 25 returns the follows:
Update 3 Here was a test, which worked well: I did receive the test mail in the inbox of softtitmur#gmail.com. However, if I redo the test in Update 1, there is still DNS requested time out.. And test.php still cannot send the mail...
Update 4 I just realised that in the page I followed, it is mail.vsysad.com under nslookup (I thought it was mail vsysad.com, that is why i tried mail www.google.com which did not make sense). So it works also in my server, and there is no DNS request timed out.
Then, I double checked php.ini, I realised that sendmail_from was not uncommented. So I uncommented it and set sendmail_from = softtimur#gmail.com, as a result, mail() of php works now, so the problem is solved, though I still don't understand FQDN and its default value (ie, WIN-RFELH8GM0KN)...
The first thing I noticed is that your SMTP Virtual service in IIS is not in a starting state so this would cause an issue. Make sure this service is in a starting state before testing.
The FQDN name is mainly used for the SMTP banner which the sender will be presented when connecting over port 25 to your server.
It maybe worth installing the DNS role onto your server and create a forward lookup zone referencing a fake domain e.g test.com and create an a record within this zone called SMTP using your servers IP. Make sure to then set your server to use 127.0.0.1 as the DNS provider so it can check record before delegating the reponse to root hints/external dns forwarder.
You need to do an SMTP request using Telnet to confirm SMTP is listening on port 25. You can do this by using the localhost ip address (127.0.0.1) as shown below:
telnet 127.0.0.1 25
helo test.com
MAIL FROM: ****YOUR EMAIL ACCOUNT****
RCPT TO: ****SENDERS ADDRESS****
DATA
You would probably not receive the email from your relay to GMAIL due to SPF Record which is in place that only allows certain IP/hostnames to send as google.com, but for testing you should see your server receive the mail after data has been inputted.
Here is the guide for using telnet on your server. Just make sure you have telnet feature installed as this is not installed by default.
http://www.yuki-onna.co.uk/email/smtp.html
Additional:
telnet localhost 25
After the SMTP banner type the following command in but make sure not to make any mistakes or else you'll need to probably start your sesssion all over again.
helo test.com
You should then see a 250 response to say the server is listening
The type the following:
MAIL FROM: test#test.com
It should respond with OK. If so, then type:
RCPT TO: ***YOU EMAIL ADDRESS OF CHOICE****
Again, it should respond with OK. If so, type the following:
DATA
Press enter after the DATA command. Your now into the body of the email. For testing purposes we will miss the subject bar and just add some data to the body.
This is a test email.
Then to complete the email you need to leave a blank line by pressing return, then a full stop, then return again like so.
***BLANK LINE****
.
***Hit Return****
Screenshot all the commands but you can blank out the email so I can see the output.

Mails Going to spam even after adding SPF and DKIM

I've configured Webmail in Cpanel, and enabled SPF and DKIM, but still the mails are going to spam in gmail. Yahoo is receiving the mails in inbox. My Domain and IP are not blacklisted. Please let me know if anyone knows the solution.
Nerdy Bird here! Have you by any chance tailed any of the exim error logs?
Try this:
Assuming you have root access to the server, ssh into the server as Root, the run the line below (NOTE: username is the beginning of the email address 'john#somedomain.com'. So in the below example, you would replace username with john). This makes searching the logs much easier).
tail -f /var/log/exim_mainlog | grep -i username
Upon running the above line, send an email from your webmail account to another account (Gmail in this case). Once you've done that, output should display in the terminal. The output is the best insight into your mail issue.
Also, if you have command line access, try using telnet. If you can connect by running the following line, you can rule out issues with outgoing ports on the server.
FOR PORT 25:
telnet alt2.gmail-smtp.in.l.google.com 25
If you get a connected message, port 25 is open and able to send mail.
FOR PORT 26:
telnet alt2.gmail-smtp.in.l.google.com 26
If you get a connected message, port 26 is open and able to send mail.
Other Possible Issues
You could possible not have a RDNS (reverse dns record) setup for your server's/domain's IP address. If not, please consult with your Hosting provider to see that gets added and allow time for propagation.
Port mail is being sent on is by default port 25. Sometimes ISPs' block mail coming from port 25. Try changing this port to port 26. This is typically done via command line or in WHM (Webhost Manager). If you do not have access to WHM or CMD, contact your hosting provider.
Although you stated your IP is not blacklisted, please check again. We use MXtoolbox.com
Hope this helps. Need more let us know.
Nerdy Bird
In my case, I tried a whole lot of things but at the end, I verified my site in https://www.google.com/webmasters and added it as a property after which email from my webmail started going to Gmail inbox again instead of spam.

Debug smtp connection

I am using the perl module Net::Smtp_auth to send a mail to myself using the web.de SMTP server on port 25 (no encryption). It works well my computer. But I would like to use the same script to send notification messages about finished jobs on a different machine where I don't have root privileges. On this machine I get a timeout for the connection. I wonder in which way the connection is blocked, what might be the reason to block it (prevent spamers?) and if there might be a way to circumvent the problem. I have some linux tools available but no nmap.
Might the connection be influenced by proxy settings and, if yes, how do I tell it to SMTP_auth?
The perl script is basically the SMTP_auth example from cpan. But I do not expect that it is relevant here:
#!/usr/bin/perl -w
use Net::SMTP_auth;
$message=$ARGV[0];
$smtp = Net::SMTP_auth->new('smtp.web.de') or die "Failed to open SMTP connection: $!";
$smtp->auth('CRAM-MD5', 'adress', 'password');
$smtp->mail('adress#web.de');
$smtp->to('adress#web.de');
$smtp->data();
$smtp->datasend("To: adress\#web.de\n");
$smtp->datasend("From: adress\#web.de\n");
$smtp->datasend("\n");
$smtp->datasend("$message\n");
$smtp->dataend();
$smtp->quit;
If the other machines are in a different network than your home machine, it may well be that the ISP there is blocking outgoing port 25 to anything but their own SMTP servers, as that is a common spam-mitigation technique. The established convention is that for outgoing mail across networks, one should use port 587 (the SMTP submission-only port) instead.
An easy way to verify if the problem is your program or not is to try to telnet to that host and port. If telnet doesn't connect but other services do, your ISP is filtering port 25.

DNS Server Refusing Connection

I am implementing a dns client, in which i try to connect to a local dns server, but the dns server is returning the message with an error code 5 , which means that its refusing the connection.
Any thoughts on why this might be happening ?? Thanks
DNS response error code 5 ("Refused") doesn't mean that the connection to the DNS server is refused.
It means that the DNS server refuses to provide whatever data you asked for, or to do whatever action you asked it to do (for example a dynamic update).
Since you mention a "connection", I assume that you are using TCP?
DNS primarilly uses UDP, and some DNS servers will refuse all requests over TCP.
So the solution might be as simple as switching to UDP.
Otherwise, assuming you are building your own DNS client from scratch, my first guess would be that you are formatting the request incorrectly. Eventhough the DNS protocol seems fairly simple, it is very easy to get this wrong.
Finally, the DNS server may of course simply be configured to refuse requests for whatever you are asking.
explicitly adding the network from which i wanted to allow-recursion fixed this problem for me:
these two lines added to /etc/bind/named.conf.options
recursion yes;
allow-recursion { 10.2.0.0/16; };
Policy enforcement?
The DNS server could be configured to accept only connections from certain hosts.
Hmm, if you're able to access StackOverflow you have a working DNS server SOMEwhere. Try doing
host -v stackoverflow.com
and look for messages like
Received 50 bytes from 192.168.1.1#53 in 75 ms
then pick the address out of that line and use THAT as your DNS - it's obviously willing to talk to you.
If you're on Windows, use NSLOOKUP for the same purpose. Your name server's address will be SOMEwhere in the output.
EDIT:
When I'm stuck for a DNS server, I use the one whose address I can remember most easily: 4.2.2.2 . See how that works for you.
You might try monitoring the conversation using WireShark. It can also decode the packets for you, which might help you determine if your client's packets are correctly encoded. Just filter on port 53 (DNS) to limit the packets captured by the trace.
Also, make sure you're using UDP and not TCP for queries; TCP should be used primarily for zone transfers, not queries.

Limit dev environment to e-mail only certain domains for testing (XP smtp IIS)

I'm developing a website on an XP virtual machine and have an SMTP virtual server set up in IIS -- it delivers mail just fine. What I would like is to confirm that any emails the site sends are only going to a specific domain.
The XP firewall seems to only involve incoming connections, I can't block outgoing TCP on port 25. And I haven't been able to configure the SMTP server to filter by delivery address.
With this setup, is there any easy way to filter outgoing email by destination address?
Here's one idea:
Under Advanced Delivery options (SMTP Virtual Server Properties > Delivery tab > Advanced). There you can set a "Smart Host" which is the SMTP server that will be used to actually send the mail, so you could possibly have it deliver directly to the specific domain's incoming SMTP server.
I think the easiest way would be to add a check to your mail sending code on the website (there's got to be some class which is in charge of sending the mails out).
You could include a check which is only active when the code is compiled in debug mode (using compiler directives). Thus, when you are developing and building the site in debug mode, this code checks if the outgoing messages are valid (specific domain) or not. If they are it lets them go, else it doesn't send the mail.

Resources