3

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?

4
  • it takes "." as end statement are you providing it ?
    – Pratap
    Sep 15, 2014 at 13:23
  • Depending on the mail version IIRC you need to end the message with a new line containing a single . dot when you run mail interactively.
    – HBruijn
    Sep 15, 2014 at 13:24
  • Tried adding . 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. Sep 15, 2014 at 13:25
  • 2
    You can check if it is a Putty problem by simply logging in to virtually anything (bash, zsh, mysql, whatever) and pressing Ctrl+D. This is equivalent to typing exit so it should log you out. If you don't get logged out, it might be a Putty issue. However, if your mail program doesn't send e-mail after feeding the body through a pipe, then it's more probably a mail issue.
    – Erathiel
    Sep 15, 2014 at 13:54

3 Answers 3

2

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.

1
  • 1
    Tried 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
3

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.

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .