Mailx Email Issue

Hello,

I am facing an issue with email in Linux. I am using mailx command to send email.
When I give invalid domain address then it is taking both sender and recipient as sender email and trying to send email.
Below is my command

echo -e "${EMAIL_TEXT}" | mailx -v -s "${SUBJECT}" -r "${FROM}"  "${TO}" >$EMAIL_RESP

here FROM=testuser@gmail.com
TO=123415@atxtxde.cosdlfmsdogfsdkfc..ocmd

Below is the response

123415@atxtxde.cosdlfmsdogfsdkfc..ocmd... Invalid host name

220 xxxx ESMTP AT&T sendmail 8.14.5/8.14.5; Tue, 27 Nov 2018 09:25:55 -0800
>>> EHLO xxxxx
250- xxxx localhost.localdomain xxxx, pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 16000000
250-DSN
250-DELIVERBY
250 HELP
>>> MAIL From:<> SIZE=1467
250 2.1.0 <>... Sender ok
>>> RCPT To:<testUser@gmail.com>
>>> DATA
250 2.1.5 <testuser@gmail.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 wARHPtoW011748 Message accepted for delivery
testuser@gmail.com... Sent (wARHPtoW011748 Message accepted for delivery)
Closing connection to ..
>>> QUIT

Can anyone please help?

sendmail/mailx/etc differ wildly from implementation to implementation. Mine doesn't take -r at all. Which you have depends on what your local system's MTA, i.e. mail server, is. What is it?

Thanks for the response. Can you please suggest how should I check for running mail server? I tried this netstat -ltnp |grep :25 but it shows tcp with some ip's.

ps aux and see what processes are running perhaps. If you're the administrator, you can just check what programs you installed.

I see something as below related to mail. Does this information enough?

smmsp 5448 0.0 0.0 23528 672 ? Ss Nov25 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue

That might be sendmail, maybe... which doesn't provide mailx. So I'm not sure which third-party mailx you have.

The sendmail utility should work also:

sendmail "${TO}" <<EOF
To:  ${TO}
From:  ${FROM}
Subject:  ${SUBJECT}

${EMAIL_TEXT}
.
EOF