1

I want to send email with mail command, but it didn't work.

I use the following command :

mail -v -s "test" [email protected]

then the terminal will always wait and no response. Also, there is nothing in the /var/log/mail Can anyone help me ?

Thanks

By the way, my operating system is debian

1
  • Also, I can ping smtp.163.com .
    – yaronli
    Apr 12, 2012 at 6:02

2 Answers 2

4

After that command, the process running mail is waiting for input on stdin, that you should end with Ctrl-D (end of file).

You can also pipe or redirect or use a here document

Exemple of using a pipe:

 date | mail -s "now is" [email protected]

Typing a message

 mail -s "a message" [email protected]
 body of your message
 end it with Ctrl-D

Redirecting a file containing the body

 mail -s "a message in file" [email protected] < mailbody.txt

Using a here document

 mail -s "a here doc" [email protected] <<ENDMSG
    this is the here doc
    ended by the line below
 ENDMSG
5

mail is an interactive program if you don't feed something into the standard input. Therefore you have to interactively enter some message body and finish the text by a line containing only a ..

E.g.:

mail -v -s "test" [email protected]
Some text
.

Or you could pipe some text into mail's standard input:

echo "some text" | mail -v -s "test" [email protected]
0

You must log in to answer this question.