I am trying to test the mail capabilities of my server. I simply do this mail -s "This is a test" [email protected]
, then it prompts me for Cc:
then the body. After typing I am hitting Control + D, however it seems that it is not exiting in the body. What am I missing here?
3 Answers
You can send a mail with a single line
echo "This is the mail body" | mail -s "This is the subject" [email protected]
without the need of any further typing.
-
1Tried this and it seems that it doesn't proceed. It seems like I need to type a body message. Sep 15, 2014 at 13:27
This may happen because of misconfiguration of mail
.
To understand the problem, turn on the debug regime, e.g.:
$mail -s "test" [email protected] --debug-level=3
Cc:
Hello. This is a test.
.
.(doesn't work until Ctrl+D, I'm using mailutils package)
.
sendmail (/usr/sbin/sendmailn
source=system, name=user, passwd=x, uid=1000, gid=1000, gecos=,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
source=system, name=user, passwd=x, uid=1000, gid=1000, gecos=,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
mu_mailer_send_message(): using From: user@example
Sending headers...
Sending body...
^C
(note the misconfigured user@example)
So the process stops sending body. You can also examine /var/log/mail.{err,log}
. To configure smtp properly, see e.g. this.
In addition to Yaroslav's excellent answer from 2016, a common misconfiguration is that the hostname is not configured correctly. Sendmail requires a fully qualified domain name to send mails, but is easily tricked into believing that the hostname myhostname
is such by adding that name to the first line in /etc/hosts
, as described here: https://linuxconfig.org/sendmail-unqualified-hostname-unknown-sleeping-for-retry-unqualified-hostname
mail
version IIRC you need to end the message with a new line containing a single.
dot when you run mail interactively..
in it still I got no response even if I keep on pressing the Control + D. Seems that Putty is not sending the keyboard press the right way.exit
so it should log you out. If you don't get logged out, it might be a Putty issue. However, if yourmail
program doesn't send e-mail after feeding the body through a pipe, then it's more probably amail
issue.