PEPS mail, smtp able to send email externally but not receiving - email

I'm currently trying to setup PEPS on my server, and having a problem receiving email sent from an external address.
I'm able to send and receive email internally fine, and i'm also able to send email externally, but I never receive email sent from an external address.
I can telnet in to port 25, but I get
connection to host lost
at the end of
HELO example.co.uk
MAIL FROM: address#other.co.uk
RCPT TO: aname#example.co.uk
DATA
Subject: Test
<ENTER>
test Message
.
After i've typed the '.' I instantly get the connection to host lost message
My servers setup using nginx, with multiple sub-domains, i've got PEPS running on mail.example.co.uk via a reverse proxy, and that bit works fine.

Related

How to setup minimal smtp server on localhost to send messages to other smtp servers

Honestly, I think I have a fundamental gap in understanding how SMTP works. I can't seem to find a good explanation of what is happening behind the scenes and I think this is preventing me from being able to do what I am attempting to do.
To explain, I'm trying to setup an application which sends notifications to users by connecting to an SMTP server. Fair enough. I figure, since I'm using my own domain, I have SPF/DKIM/DMARC configured, I can add an MX record for the host I set the application up on (my SPF record has the mx keyword to authorize any hosts in my MX records to send/receive mails). Then, I can have that same host run a super lightweight SMTP server that can accept mails from the application, and send them on to recipients.
Almost crucially, I want this server to basically just run on localhost so that only this application can connect and send mails through it, but so that it can't really "receive" mails sent to my domain (I have set the MX priority very low (well, a high number) for this app server). I figure since I'm running my own SMTP server, that I don't really need to authenticate against it (it's running on localhost), just take in any mail and send it on to recipient domains.
When sending on to recipient domains... does the SMTP server need to authenticate to say, the gmail SMTP server as a user in order to send mails over there? That seems weird, since it's not a user logging into gmail to send mails, it's an SMTP server that is authorized within SPF sending mail from my domain (From address from my domain as well) to where ever the app server user's email is based (in this example, the user would be e.g., some_user#gmail.com).
I tried using python's aiosmtpd command-line and telnet to send a mail from test#MY_DOMAIN.TLD to test#MY_DOMAIN.TLD and it didn't seem to deliver the message; I figured aiosmtpd would connect to the preferred MX servers for my domain (my "real" MX's) to transfer the message, which would then put it in my inbox. That didn't seem to be the case, and I'm not sure why.
Exact repro steps, where example.com is my domain, and terminals are running on a box with a hostname listed in my MX records.
Terminal A:
$ aiosmtpd -n
Terminal B:
$ telnet localhost 8025
EHLO <example.com>
MAIL FROM: test#example.com
RCPT TO: test#example.com
DATA
FROM: Application Notifications <test#example.com>
TO: User Name <test#example.com>
SUBJECT: App Notify Test
This is a test!
.
QUIT
How do SMTP servers normally send mail between each other? Do they each get some login to each other's SMTP servers to authenticate with, and since I'm not doing that, this is a problem? Can I run a SMTP server on localhost and have it send mail out of the network without receiving mails (a no-reply service)? Is there something obvious that I'm just missing here that solves all my problems?
Thanks
It sounds like you want to run a mail transfer agent (MTA) that relays email to remote SMTP servers. An MTA will typically act as an SMTP server to receive messages, and then it will act as an SMTP client when it relays the messages to remote hosts.
MTAs generally operate in two different modes: (1) They will relay messages from authenticated users to remote hosts, and (2) they will receive messages from remote hosts to its users and store them somehow. The combination of those two modes - where the MTA will accept messages from remote hosts and relay them to different remote hosts - is called an open relay and is sure to attract spammers and place your server on spam blacklists.
aiosmtpd is not an MTA or an email relay out of the box - it is merely an SMTP server that will receive messages and do whatever with the messages you program it to do. By default it will do nothing - that is, it will receive the messages and throw them away. If you want to implement an email relay in aiosmtpd, then you need to implement the SMTP client portion of the MTA, e.g. by implementing an aiosmtpd handler that instantiates smtplib.SMTP to connect to remote hosts.
However, if all you want is an email relay, then you most likely don't need aiosmtpd at all - postfix is probably a better choice.
aiosmtpd can be a good choice if you need to implement mailing list software or perform some automation tasks based on incoming emails from e.g. cameras or scanners.
If you want to implement an email relay in aiosmtpd, then you need to ensure that both the software and your server are configured in a way that you don't relay unauthenticated messages from the outside internet.
See also: Python aiosmtpd - what is missing for an Mail-Transfer-Agent (MTA)?
So, I actually figured out what was missing here.
I need to run an SMTP server, yes, but I also needed to write code to parse the "to" domain (the recipient domain), perform a DNS request for the MX server(s) of the recipient domain, and then use the smtplib client to then send mail over to the recipient domain. Authentication is not needed to relay that message to the recipient server, authentication is only required for reading from a given inbox or authenticating a sender to send on behalf of a domain (I trust myself and myself only to send mail). I can do all this while also only listening for mail on localhost so that only my local server can use the local SMTP server for relaying messages/emails off to recipient domains.
Additionally, I don't need to have my external IP listed as an MX server since it's not accepting mail for the domain, only sending. I do need an SPF record for it though so that it is an authorized relay/sender for email from my domain.

Setting up hMailServer to send and receive email

I'm trying to configure hMailServer on my computer to be able to send email out and also receive emails. I'm not sure if I have everything set up correctly as some tests works and some others do not so I am confused.
I have already set up in the DNS of my domain these 3 MX records:
mail.example.com
smtp.example.com
imap.example.com
Each one of those records points to the domain name of my server. I am able to connect to the web server of my domain. In my router, I have forwarded ports 25, 110, 143, 465 and 587 to my local computer running the hMailServer application. When running a port check on the web, it looks like port 25, 110 and 465 are blocked, but the rest are not.
If I open my Mozilla Thunderbird mail client, I set up an account I created in hMailServer for the domain in question.
I have also allowed the hMailServer application through my Windows firewall for both the private and public networks. I did the same for the Thunderbird email client.
I can locally send emails to myself and other local domains set up in hMailServer. However, I cannot send or receive any email to/from external recipients, like to/from Gmail or Hotmail for example. I'm getting this error message:
Error Type: SMTP
Connection to recipients server failed.
Error: Host name: 1.1.1.1 (edited) message: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Here are the TCP/IP ports summary in hMailServer:
The second part of my question is once I can actually send and receive email to/from external domains, how would I secure the connection (SSL/TSL...)? I already have a SSL certificate for my web server (example.com and www.example.com). Do I just need to generate another one for say mail.example.com or do email servers use a different kind of certificate?

Questions about email reverse DNS check

Our email server was blocked, I need find a way to solve this.
About the outbound SMTP IP, when I send emails from my email server, if I send them to a SMTP relay on my other server, which IP the receive side will check for the reverse DNS? the email server IP or the relay server IP?
The receiving mail server will do a reverse dns check on the mail server that it received the message from. So, if your mail server sends a message through a relaying mail server, which then sends the message to the receiving mail server, the receiving mail server will do a reverse dns check on the relaying mail server.
The reverse DNS check works like so: Say the receiving mail server receives an incoming connection from 209.85.160.179. The receiving mail server will do a reverse DNS lookup on this IP, which (in this case) will resolve to mail-yk0-f179.google.com. To confirm that the sending mail server is in fact in the google.com domain (and 209.85.160.179 is not run by a spammer or spoofer who simply setup a PTR record for 209.85.160.179 that points to mail-yk0-f179.google.com), the receiving mail server then does a forward DNS lookup on mail-yk0-f179.google.com, to make sure that this FQDN does in fact resolve to 209.85.160.179 (a spammer would not be able to setup a DNS record for a FQDN in google.com's domain).
So, legitimate senders should have a PTR record setup for the IP address that their mail server sends from, and the FQDN that the PTR record points to should resolve back to this same IP. This is how spam filters identify mail from home computers that have been taken over by bots or zombies for sending spam - as most IPs used for home internet connections will not pass a reverse DNS check.

SMTP Mail Failures to a certain domain

Do the SMTP logs on a server (Windows 2003) only show logs of mail that were sent successfully?
We are getting bounce backs when sending mail to a particular domain:
The connection was dropped by the remote host.
It looks like a problem on the receiving server, but we dont have much information to provide them. We can send to hotmail, gmail, yahoo etc OK.
Any ideas?
Most likely, there is a spam filter in front of the receiving mail server for this domain, and this spam filter thinks your mail server is sending spam, so it's closing the connection from your mail server. One way to test this is to simulate sending a message to this mail server by opening a command prompt on your mail server, and use telnet to connect to the receiving mail server on port 25, and proceed with the process of sending a message just as a mail server would. This way, you'll be able to see how the receiving mail server responds after each step. Follow the instructions in http://support.microsoft.com/kb/153119 to see how this is done.
It turned out the sending server was blacklisted by McAfee, that was running on the receiving servers firewall.
For those that may have the problem in the future you can check if your server is blacklisted with McAfee here:
http://www.mcafee.com/threat-intelligence/ip/spam-senders.aspx
After entering your server IP, you should see a link Threat Feedback. Use this to email McAfee.
I was able to send McAfee an email with an explanation, they then removed our server from the blacklist.

Working of receiving mail server

Dear, I torn my hair since last 7-8 days to know the working of receiving mail server. The word "Receiving Mail Server" might sound confusing to you in the first instance. So let me first make you clear on that.
Complete Mail service works as follows:
We send email using a MTA (mail transfer agent) like "sendmail" on Linux or "Outlook" on windows.
Both these MTA deliver email to the SMTP server, which further delivers the email to the destination.
Let say we are sending email to "munendra#mydomain.com", SMTP must connect to the domain "mydomain.com" on some TCP socket, and there must be some service listening on the server "mydomain.com" to receive the emails. I want to know what this service is?? On what port does it runs??
This stage is what I mean to say the "Receiving Mail Server".
POP/IMAP comes secondary after the email delivers on the server, their primary function is to fetch the email from server to the local computer.
Thanks a lot in advance!!
That service - which listens to receive e-mails on mydomain.com - will be the local SMTP service, which listens on TCP port 25.
You send e-mail through SMTP protocol to an SMTP server which receives your e-mail from your SMTP client. The SMTP service will deliver/store it for the appropriate mailbox, ready to be picked up - over a different protocol, POP3, IMAP - by the mail client.