sendmail and MX records when mail server is not on web host - email

This is a problem I'm sure is easy to fix, but I've been banging my head on it all day.
I'm developing a new web site for a client. The web site resides at (this is an example) website.com. I have a PHP form script to email visitors' requests to requests#website.com.
When I coded this on a staging server on a different domain, all worked fine. When I moved it to website.com, the mail messages never arrived. The web server is on a virtual host with a major ISP.
Here's what I've learned since then: My client's mail server is Microsoft Exchange on a box physically in their office. Whenever someone on the outside world emails requests#website.com, the mail arrives. But if the web server sends to the same email address, it fails every time. This is not a PHP problem. I secure shell in to the web server and have tested this both with sendmail and the UNIX mail application. I've also tested it by emailing various email accounts from the shell. I can email myself, for example, just nobody at the website.com domain.
In short, when I'm logged in to website.com, mail to requests#website.com, user#website.com, another_user#website.com all fail. All other addresses work fine. What I've discovered is those dropped emails are routed to the web server's "catchall" account where they sit in its inbox.
I've done an MX lookup on website.com. The MX record points to mailsec.website.com. I can telnet to mailsec.website.com port 25 and see the SMTP server.
It appears to me that website.com isn't doing an MX lookup when it's sending mail to requests#website.com. My theory is that it recognizes the domain as local, sees that there's no "requests" user account to deliver it to, and drops the mail into the catchall account. What I want is to force sendmail to do the MX lookup and send the message on to the Exchange server. I'm at wit's end here. I can't figure out how to do this.
For that matter, I may be way off base here and have misdiagnosed this entirely. Internet mail and MX has always seemed a black art to me, and my ignorance is certainly showing in this question.

I think the problem is that sendmail (your process) is talking to the local sendmail daemon. The local sendmail daemon thinks that because it is website.com, it should know how to deliver the email. Unfortunately, the actual address in the to field does not exist on the web server and thus it dumps it in the "catchall" mail box. You should talk to your ISP and have them update their sendmail configuration so that mail addressed to ...#website.com gets forward to the mail exchanger instead of being handled locally.

Sendmail by default guesses list of local email domains.
It can be turned off using the following line in your sendmail.mc file:
define(`confDONT_PROBE_INTERFACES',`True')
As root list local email domains before and after the change using:
echo '$=w' | sendmail -Am -bt
You will see which domains should be added "manually" to (usually) /etc/mail/local-host-names file after disabling auto-guessing.
After changing sendmail.mc:
Generate/compile new sendmail.cf file
Restart sendmail daemon (or send HUP signal)

tvanfosson basically has it, but as a temporary workaround, you should be able to change your script so that it mails 'user#mailsec.website.com', and then the mail will get delivered to the actual mail server.

Edit the tsm.cf file (in /etc/mail/ or similar) to include
FEATURE(relay_entire_domain)
between the DOMAIN() and MAILER() lines. Since you're editing the file, you may want to also improve security with
define(`confPRIVACY_FLAGS',``noexpn,novrfy'')
After changing the tsm.cf file (or any sendmail config file), restart or SIGHUP the sendmail process.
This change is necessary because the WWW and MX servers for the domain do not exist in the same process space; this FEATURE triggers sendmail to process messages for the domain using it's external delivery mechanism.
The edited portion of the tsm.cf file should look similar to this:
DOMAIN(website.com)dnl
FEATURE(relay_entire_domain)dnl
define(`confPRIVACY_FLAGS',``noexpn,novrfy'')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl

What worked for me was to add an MX record on the webserver hosting the website, that points to the host assigned on the original domain name server. In the case presented here would be an mx record pointing to: mailsec.website.com

I'm new here. Wanted to extend RB_CWI answer, but I am not allowed to comment.
His solution worked great.
You are not required to define the DOMAIN().
However, on my system I was required to install the sendmail-cf package.
The instructions below were done on CentOS 6.5
First, install sendmail-cf
sudo yum install sendmail-cf
Then, edit the senmail.mc
sudo vi /etc/mail/sendmail.mc
At the bottom of the file add FEATURE(relay_entire_domain)dnl, so it looks like:
...
FEATURE(relay_entire_domain)dnl
MAILER(smtp)dnl # right above this line
MAILER(procmail)dnl
dnl MAILER(cyrusv2)dnl
Save the file, and restart sendmail.
sudo service sendmail restart

Got stuck on the same problem. MX points to an external Exchange server but php/sendmail did not lookup this record. Instead mails posted by WordPress on this webserver dropped in the catchall-mailbox.
Solution was to delete ALL mailboxes on the webserver. Now sendmail was interested in the MX and all mails went to the Exchange.
However, the Exchange uses the webspace's mail server as SmartHost for outgoing mails. As solution for this, we were able to use the FTP credentials for accessing the mail server. I assume this solution does not work on every provider on this planet, but in our case (all-inkl.com) it worked out.

Related

Local email to root should not leave the host

I am trying to set up the most simple email server on an Amazon Linux 2 host for simple outbound mail (e.g. sending system messages). Following instructions on the net, I have installed mailx and sendmail. I am not committed to either package, I just want a simple setup with a minimal footprint. I have no problem switching to postfix if that is a better solution.
For configuration I have made the following changes.
/etc/sysconfig/sendmail:
DAEMON=no
/etc/mail/submit.cf (hostname obfuscated):
D{MTAHost}smtp.******.com
This works fine, and I am able to receive mail that is sent from the system.
There is a wrinkle. The anacron process is sending mail to the root account. However, rather than the mail being kept internal to the system it is being sent to the SMTP server. The SMTP server sends the message back to my host, which doesn't accept mail, and a loop is created when an 'undeliverable' message is send back to root on the host that doesn't accept mail.
How can I configure my system so email to root stays local and is not sent to the SMTP server? Any other 'best practices' suggestions would be welcome as well. And again, if switching to postfix is better, I am willing to do so (but will need configuration guidance).

How to connect my Mac Mail to my domain which his DNS are handled through DigitalOcean?

I bought a domain.
I pointed his name servers to:
ns1.digitalocean.com
ns2.digitalocean.com
I have added a CNAME record point to #
I want to send and receive emails using my Mac mail program.
I know that I should probably build a full mail server which is an awful thing to do.
Therefore, I have another server (not digitalocean) running on cPanel. In this cPanel I have a very powerful cPanel's mail server.
How can I point my digitalocean CNAME to the remote server where the cPanel is?
I hope it's clear enough.
In order to make your domain points to the digital ocean server, you will have to create A record that points to the IP of that server, same goes to any subdomain.
Regarding your mail server, you need to make mail.mydomain.com points to the IP of your cPanel server using A record not CName and also modifying other records like SPF/DKIM records.
For your local mail client you can get the configuration by logging into the cPanel user account and view the mail settings

Sendmail Relay Issue

I have installed sendmail on Centos 7 and setup relay server using SMART_HOST.
But sendmail is not using my relay server when sending email, it keeps using localhost.
Can anyone help me to solve this problem?
Sendmail-8.12+ by default relays messages submitted locally to local main sendmail daemon running at 127.0.0.1:25. It does it as a security precaution to avoid installation as set root uid.
Have you checked sendmail log files? They should show where main local sendmail daemon relays messages to non local email addresses.
Documentation: SECURITY file in sendmail distribution
I found the answer myself.
The mistake was with LOCAL_DOMAIN.
I had put my local domain (which was used for mail server and email address) here.
And all of my emails were being handled as local emails.
Local emails were meant for excluding from relay, lol.

Accept All Incoming Email Messages on Server

I want to write some email scanning software and don't understand how to setup my server. I have a hosted web server running Windows 2003 Server. It is running the Default SMTP Virtual Server with a fully-qualified domain name of abcdef.com (example). DNS is pointing abcdef.com to my server. If I spoof an email from my desktop pc so that it appears to come from info#abcdef.com, and I send the email to a 'non-existant' email address then the bounceback does arrive on my web server and is stored in C:\inetpub\mailroot\Queue on the server - great! (I can scan it and handle the bounceback). However, if I simply send an email straight to info#abcdef.com then it does not seem to get placed anywhere on the server. I don't understand why bouncebacks get stored but other incoming email doesn't. I'm keen to avoid having to install any 'email server software' on the server, as I want to keep things as clean as possible. All I really want is some way of telling the server to accept all incoming messages to abcdef.com so that I can process them myself, and to place the .eml files in a known directory that I can scan. I'll then write an eml file parser to process the files.
Thanks very much.
A possible reason for the lack of delivery is that your domain has a DNS A record, but no DNS MX record. MX records are used for delivery of mail. Historically, if no MX record was present for a domain, mail servers were supposed to fall back to looking for a domain's A record.
In your case, I'd guess that your local mail-sending software is looking for an MX record and then stopping if it doesn't find one, whereas the remote system sending you the bounce is looking for the MX record and then looking for an A record when it can't find one.
The Wikipedia article on MX records has more details.
SMTP is a message transfer agent (MTA), responsible only for handling the transfer of mail from one point (the client, perhaps) to another (the mailbox server, such as a POP or IMAP server). SMTP servers aren't the right tool for ultimately handling mail coming INTO a domain -- they only handle transferring the mail coming into a domain to another app, such as the aforementioned POP or IMAP server, which then know how to sort and store that mail.
In short, the Default SMTP Virtual Server isn't the tool you're looking for for your project.
From this other StackOverflow question, it looks like there are a few SMTP servers which are intended for development use but which might serve the purpose you seek -- they accept incoming messages and then write them to files (in some manner, and with some tweaking).
Ok, working now. Issues were as follows:
There was no MX record, so external email wasn't being directed to the server. The .EML file that existed on the server was indeed placed there by an outbound email process.
The firewall was blocking port 25 - now opened.
It is necessary to have some sort of inbound email service running on the server. Windows Server has a lightweight POP3 service which you can configure to place all incoming email into a single 'catch-all' mailbox. This fills with .EML files, which can then be scanned by our custom service.
Many thanks to delfuego & Jon.

automation: email yourself a file

I have a computer at home which I can't access from work. I'd like to be able to view results from work that my home computer produces. The best idea I've come up with is an automated script running on my home computer that emails myself the results (from a text file or stderr/out) when complete.
I'm decent with bash (I have a linux machine) and java, so an answer using either or both of those would be ideal, but if there's something easier that's fine too.
I typically use gmail, but also have yahoo mail.
My question is this: what would be the basic steps in solving this problem? I can do the nitty gritty stuff, but can't really get the big picture of how something like this would work.
Please help.
jbu
Howto set up ssmtp to send through a Gmail account
Some of the steps here might seem strange at first, but the rationale is put
in footnotes that should hopefully explain why.
First create a spare account on gmail which you will only use for
sending email. For instance, if your normal account is user#gmail.com,
create an account user.noreply#gmail.com with a newly created password
which you only will use for this account [1].
Set up the new account to forward all email to the normal account [2]
and under account settings you should add all other email adresses you
use [3].
Then install ssmtp (On Debian: aptitude install ssmtp) and edit ssmtp's configuration file /etc/ssmtp/ssmtp.conf:
root=user#gmail.com
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=user.noreply
AuthPass=passwdusedonlyforthisaccount
FromLineOverride=YES
and configure the local mail delivery by editing /etc/ssmtp/revaliases
assuming that your local login is localuser:
root:user#gmail.com:smtp.gmail.com:587
localuser:user#gmail.com:smtp.gmail.com:587
Make sure the two configuration files are readable to all users who
should be able to send email [4].
Test the setup by e.g. mailx (On Debian: aptitude install bsd-mailx):
echo 'testing, one, two' | mailx -s 'test 1' user#gmail.com
Hope this helps.
[1] The new gmail user name and password will be visible to everyone who
can log onto your machine, so you do not want this account to be
critical in any way, meaning you can close it down immediately if
someone should get access to it.
[2] If some email you sent bounces back to you, you might want to know
about it, and there actually exists people who will happily reply to an
email from johnsmith.noreply.
[3] Gmail will rewrite the From header on the email if it does not recognise the address.
[4] Ssmtp runs as the local user who sends the email, so that user needs
read access to the configuration files.
On any Linux I have used the mail sending from command-line is simple:
mail -s "My subject here" recipient#wherever.com <message_body.txt
AFAIK this acts as a front-end to sendmail, and you have to have sendmail configured to forward the messages to your ISP mail server.
You can't access your home computer from work which rules out a "remote support" option.
Can you access other computers on the Internet? If so, you could simply set up one of the online storage options and then ftp the results from your home computer. That's a lot simpler then trying to write scripts or code to generate emails with attachments or whatever.
You could then view the external computer from work.
If you have netcat, this command will send you an e-mail:
Given a file in this format (from Wikipedia):
HELO relay.example.org
MAIL FROM:<bob#example.org>
RCPT TO:<alice#example.com>
RCPT TO:<theboss#example.com>
DATA
From: "Bob Example" <bob#example.org>
To: Alice Example <alice#example.com>
Cc: theboss#example.com
Date: Tue, 15 Jan 2008 16:02:43 -0500
Subject: Test message
Hello Alice.
This is a test message with 5 headers and 4 lines in the body.
Your friend,
Bob
.
QUIT
Then netcat it to an SMTP server you have access to:
nc mail.somewhere.com 25 < file.txt
This will then send the e-mail. You can see how you can create a Java program to do this for you (just execute the commands).
Traditionaly, with unix systems like Linux, you'd have an MTA, a mail transfer agent, on the computer that deals with sending e-mail.
This could be a full blown e-mail server like exim, or something simple like ssmtp that just sends messages on to a relaying SMTP server such as would be provided by your ISP.
This isn't neccessarily the case anymore, since mail clients like Thunderbird include their own MTA, much like mail clients on Windows do.
However, it is likely that your distro will install some MTA or other by default, if for no other reason than the fact that other things on your system, like cron, want to be able to send e-mail. Generally there will be a command line tool called sendmail (sendmail being the original MTA [citation needed], other MTAs maintain compatability with its interface and it has sort of become the standard) that can be used from a shell script to send an e-mail.
My solution assumes that you have a SMTP server available which allows you to send an email programmatically. Alternatively, you can use a local install of sendmail which generally is available with most linux distros.
Create a standalone java program which watches the directory your home computer saves the file to. Use the JavaMail API to attach and send the file to any email you wish.
If you're also familiar with the Spring Framework, it has a nice abstraction layer for working with JavaMail and makes this sort of thing trivial.
Of course, your home ISP probably has the common SMTP port blocked as well.