← 返回命令列表

Linux command

sendmail 命令

网络

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Send an email

echo "Message body" | sendmail [recipient@example.com]

Send email with subject

printf "Subject: Test\n\nMessage body" | sendmail [recipient@example.com]

Send email from a file

sendmail [recipient@example.com] < [message.txt]

Process mail queue

sendmail -q

Display mail queue

sendmail -bp

Test configuration

sendmail -bv [recipient@example.com]

说明

sendmail is the traditional Unix mail transfer agent (MTA) interface. While the original sendmail program is complex, most Linux systems use compatible alternatives (Postfix, Exim) that provide the same command-line interface. The command accepts a message on standard input and delivers it to the specified recipients. Headers can be included in the input; if -t is used, recipients are read from the To/Cc/Bcc headers instead of command-line arguments. For simple email sending, the message format includes optional headers followed by a blank line and the body. Headers like Subject:, From:, To: are standard. The mail queue holds messages awaiting delivery. Use -q to trigger queue processing and -bp (or mailq) to view queue status.

参数

-t
Read recipients from message headers (To:, Cc:, Bcc:)
-f _address_
Set envelope sender address
-F _name_
Set full name of sender
-i
Ignore dots alone on lines
-q
Process saved messages in queue
-bp
Print mail queue summary
-bv
Verify addresses without sending
-bd
Run as daemon
-bs
Use SMTP protocol on stdin/stdout
-v
Verbose mode
-O _option_=_value_
Set mail server option

FAQ

What is the sendmail command used for?

sendmail is the traditional Unix mail transfer agent (MTA) interface. While the original sendmail program is complex, most Linux systems use compatible alternatives (Postfix, Exim) that provide the same command-line interface. The command accepts a message on standard input and delivers it to the specified recipients. Headers can be included in the input; if -t is used, recipients are read from the To/Cc/Bcc headers instead of command-line arguments. For simple email sending, the message format includes optional headers followed by a blank line and the body. Headers like Subject:, From:, To: are standard. The mail queue holds messages awaiting delivery. Use -q to trigger queue processing and -bp (or mailq) to view queue status.

How do I run a basic sendmail example?

Run `echo "Message body" | sendmail [recipient@example.com]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -t do in sendmail?

Read recipients from message headers (To:, Cc:, Bcc:)