← 返回命令列表

Linux command

mailx 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Send email

mailx -s "[Subject]" [recipient@example.com]

Send with body

echo "[message]" | mailx -s "[Subject]" [recipient@example.com]

Send from file

mailx -s "[Subject]" [recipient@example.com] < [message.txt]

Send with attachment

mailx -s "[Subject]" -a [file.pdf] [recipient@example.com]

Send with CC and BCC

mailx -s "[Subject]" -c [cc@example.com] -b [bcc@example.com] [recipient@example.com]

Read mail

mailx

Read mail from a specific mailbox file

mailx -f [path/to/mbox]

Use SMTP server

mailx -S smtp=[smtp://mail.example.com] -s "[Subject]" [recipient@example.com]

说明

mailx is an enhanced mail command for sending and receiving Internet mail. It is POSIX-compatible with extensions for MIME support, SMTP connectivity, S/MIME, attachments, and more features than basic mail. It handles both sending and reading email. When called without arguments, it reads the user's mailbox. When given recipients, it enters compose mode.

参数

-s _SUBJECT_
Email subject.
-a _FILE_
Attach file.
-c _ADDR_
CC recipients.
-b _ADDR_
BCC recipients.
-r _ADDR_
Set From address.
-S _VAR=VALUE_
Set internal variable (e.g., smtp, from, smtp-auth).
-t
Read recipients from To/Cc/Bcc headers in the message.
-f _FILE_
Read from mailbox file.
-N
Inhibit reading system-wide startup file.
-H
Print header summary and exit.
--help
Display help information.

FAQ

What is the mailx command used for?

mailx is an enhanced mail command for sending and receiving Internet mail. It is POSIX-compatible with extensions for MIME support, SMTP connectivity, S/MIME, attachments, and more features than basic mail. It handles both sending and reading email. When called without arguments, it reads the user's mailbox. When given recipients, it enters compose mode.

How do I run a basic mailx example?

Run `mailx -s "[Subject]" [recipient@example.com]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -s _SUBJECT_ do in mailx?

Email subject.