receiving mail on an ec2 instance (without my own domain) - email

I have an EC2 instance that I am using for a test project. I would like to send emails to it but I actually do not need to send emails from it.
I have port 25 open and have installed mailx for handling the emails. When I type mail i get No mail for ec2-user though i have already sent an email there.
My needs are real basic a few emails sent so I don't really need an industrial strength solution.
I know I also need to set up an MX record but this, I think, is where I am getting confused. So the email (at least according to github) is ec2-user#ip-XX-XXX-XX-XXX.us-west-2.compute.internal (x's replace the ip).
When I follow these instructions for setting up the MX record http://kb.kerio.com/product/kerio-connect/server-configuration/mail-delivery-and-dns-records/what-is-an-mx-record-and-how-is-it-created-1210.html, I get an error:
>[ec2-user#ip-xx-xxx-xx-xxx ~]$ nslookup
> server
Default server: 172.16.x.xx
Address: 172.16.x.xx#53
> set q=MX
> ip-xx-xxx-xx-xxx.us-west-2.compute.internal
Server: 172.16.x.xx
Address: 172.16.x.xx#53
Non-authoritative answer:
*** Can't find ip-xx-xxx-xx-xxx.us-west-2.compute.internal: No answer
Authoritative answers can be found from:
us-west-2.compute.internal
origin = ns0.us-west-2.compute.internal
mail addr = hostmaster.amazon.com
serial = 201210xxxx
refresh = 3600
retry = 3600
expire = 3600
minimum = 60
>
again x's where the ip is.
What's a direct way of just setting up the mx record on ec2 so i can receive a few emails? I don't have a domain for this other than what ec2 provides.

You can't set up an MX record in a domain you don't control... but you do not actually need an MX record when the host receiving the email is the same as the one to which the host is addressed.
You do, however, need to use your EC2 instance's external hostname, since the internal one isn't meaningful anywhere except... internally.
This will be in a form more like ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com.
Using this, you should be able to configure ec2-user#ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com as a working email address -- although, for what it's worth, you really shouldn't be using the "ec2-user" account... you should have created one of your own.
You will need more than mailx to "handle" the emails; you also need an email server like exim4 running on your machine, and that server software needs to be configured so that it realizes that ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com is a host for which it should accept incoming email.

I'm not sure that you will be able to test this without a domain, short of opening up port 25 and telnetting directly to the port.
Take a look at Receiving email with Amazon EC2? for some clues as to what you need to get started.

Related

The IP you're using to send mail is not authorized 550-5.7.1 to send email directly to our servers

I am new to DO and I have tried to look for solution online but I didn't find any answer. I am using Ubuntu OS 20.04(LTS)X64 version.
My question is that I have 2 droplets, MailServer droplet where I have installed docker composer and mailcow to run mail mails, and another droplet named WebServer hosting my domains. I have also set up all required DS records under my domain added on WebServer droplet and pointed A record mail.mydomail.com to the IP of mail server droplet. However, whenever I try sending emails they all bounce back unless the ones sending between mydomain users(user1#mydomain.com & user2#mydomain.com). It just says that "The IP you're using to send mail is not authorized.....".
Any support to help me solve this issue will be highly appreciated. An I am wondering if that approach is possible or if there is any documentation on how someone can set up dns records on one server and configure mailserver on another server using digitalocean.
Here is how I set my DNS on mydomain.com to point to MailServer IP

cPanel email routing... if not found locally try remote

I've got a weird setup with my emails that I need someones brain to look at. I've got it setup like this so that most of my emails are on one server (server1) and then 1 single account is setup on a second server hidden from the rest (server2)
Email Sent to user1#domain.me
MX record for domain.me = mail.domain.me
A record for mail.domain.me = server1 (11.11.11.11)
Email forwarding rule forwards all email sent to user1#domain.me to user#2.domain.me
MX record for 2.domain.me = mail2.domain.me
A record for mail2.domain.me = server2 (22.22.22.22) a cpanel server
Email hits my server now addressed to user1#2.domain.me
Domain forwarding rule forwards all email sent to #2.domain.me to #domain.me
This works great however my mail routing in cpanel is set to local, and therefore when sending emails out on server2 (22.22.22.22) to users#domain.me they're always delivered locally first and foremost
Is there any way around this? so that outgoing mail on this domain obey's DNS records (the mx records) and delivers it firstly to server1 (11.11.11.11) as if it was being sent from any other domain, gmail etc. Perhaps if the account isn't found locally then send on out to the web? Or perhaps there is a way to setup an alias somehow to let the local account receive mail for user1#2.domain.me
Thanks for your time & efforts looking into this
Henry
Check if your remote domains are listed in /etc/remotedomains and /etc/secondarymx. Note that if your second server has a dns server, it will try fetch the dns data locally first.
I have 2 servers using cpanel where each server acts as the other's backup and I don't have the issue you described.

Postfix attempting to bind to port 25, used for outgoing mail only (maybe not necessary?)

Not sure if this belongs on Stack Overflow or somewhere else but I'll try here first.
I have multiple servers, each with the same setup where nearly everything running on the server is in a docker container. I have two goals I would like to achieve. First, the host machine is setup to send emails for users with uid < 1000 to my external email address. Second, on one server, I have a docker-mailserver container running to handle random, seldom used emails (for log files, etc.).
It seems I can have either the host machine running postfix OR the docker-mailserver running (and bound to port 25). Currently, I have the docker container, running the mail server, full operational and everything can send and receive just fine.
However, now I am unable to start postfix on the host machine so that I can receive emails sent to the root user (things like cron output) since port 25 is --rightfully-- in use by the actual mail server receiving email.
Questions:
1) How can I tell postfix on the host to not bind to port 25? If port 25 is only used for receiving mail, why would my outgoing-only postfix config need to use port 25?
2) I am perfectly comfortable not receiving emails for the root user, if whatever would normally be sent to the root user is logged elsewhere (perhaps, syslog?). Are the emails to root only maintained as emails or are they somewhere else, negating the need for postfix on the host for forwarding to a real account?
Thanks in advance.
Specifically answering your questions first:
You should be able to have postfix listen on any port you specify by editing the main.cf configuration file and changing the smtp listener to a numbered port of your choice. Of course, if it isn't a "known" port, I'm not sure what/who will ever connect to it, but maybe you don't care in this situation as you are only using postfix as a relay?
It may depend some on the Linux distribution or setup of your host, but most systems will leave email in the local delivery "mail spool" if there is no system/daemon set up to move it anywhere else. Back when that was the normal way to handle multi-user mail on UNIX systems, a login user used a mail reader client to read through email in your local "spool", and of course if you don't have that, you can simply vi your mail file and read the raw contents if necessary. These mail files are normally located in /var/spool/mail on most systems.
Stepping away from your questions, I would guess you don't necessarily need postfix running on your host, especially as your containerized mailserver is handling the port 25 SMTP traffic for the host. Local email will stay local, I assume, without postfix, and be available through local means; and you might even find a simpler solution to external forwarding (e.g. a script that can parse mail spools and just connect to an SMTP relay and send it to an external address) if you want that.

Mail not getting send to specific domains

We have a VPS with CentOS combined with DirectAdmin which we use for a Magento shop. This runs fine, except for sending email.
Problem:
It appears that some specific domains won't receive our emails and we get a bounce. If we use any other email sending systems, the mails arrive without problems.
The bounce mail contains the following error:
SMTP error from remote mail server after HELO Company-Shops:
host mx-cluster-b2.one.com [IP ADRESS]: 504 5.5.2 :
Helo command rejected: need fully-qualified hostname
After googling and trying things for a week now, I am a bit lost. I tried checking postfix in CentOS, but this is not installed and I'm not quite sure if this is needed.
Possible issue?
I believe the hostfile in CentOS is setup incorrectly:
127.0.0.1 localhost localhost.localdomain localhost4 ... etc
OUR IP Company-Shops
'Company-Shops' should probably be a domain name, am I right? The same as the rDNS. But I'm afraid if I change this it will kill my site and whatnot. I'm not sure if this entry correlates with the 'company-Shops' helo label in the bounce error.
Some extra info:
- We use the webmail Roundcube from DirectAdmin
- At the moment we run one shop, but this might grow a bit (multiple sites on 1 IP)
- We don't use subdomains
- We've set up a reverse DNS, with the domain
Is there anyone with similiar experiences or with a bit more knowledge about this subject? I appreciate any advice we can get, as we are stuck..
Many thanks.
Yes, that's right: your mail server should identify itself using a fully-qualified domain name when it connects to send mail via SMTP. You don't say what mail server you're running, but since you're using DA, it's probably Exim. If so, you want to edit /etc/exim.conf and set primary_hostname to the FQDN of your server.
This would also be a good time to double-check that reverse DNS is set up properly for your IP address. Many hosts will also reject email from servers on IPs without a valid rDNS record.
I'm not familiar with Magento, but I can't see any way that changing the Exim configuration in this way could impact that program.

Receiving email with Amazon EC2?

I have no trouble sending out email with my EC2 server, but how can I check the email that is sent to me? I have an elastic IP setup and modified reverse DNS records. Do I need to install Postfix to receive email?
Ensure that port 25 is active and open on your server. Install an SMTP service on your instance ...postfix is mighty fine.
Ensure you have also set up some MX records if you want to receive email from the world...
I suppose the first thing to do is testing if you can open a telnet connection to port 25 on your server. Then you know if anything is listening for incoming mail.
If not, then you should probably install postfix as well as test your firewall settings (I seem to recall the EC2 having some sort of firewall setting for which ports to allow in the web interface)
edit: correct port number