← 返回命令列表

Linux command

msmtp 命令

网络

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

常用示例

Send email

echo "[message]" | msmtp [recipient@example.com]

Send email with subject

echo -e "Subject: [Hello]\n\n[Body]" | msmtp [recipient@example.com]

Send from specific account

msmtp -a [account_name] [recipient@example.com]

Test configuration

msmtp --serverinfo

Check account configuration

msmtp --configure [account_name]

Send file as message

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

Print configuration

msmtp -P

说明

msmtp is a lightweight SMTP client for sending email from the command line. It works as a sendmail replacement, enabling scripts and applications to send mail through external SMTP servers. Configuration in ~/.msmtprc defines accounts with server settings, authentication, and TLS options. Multiple accounts can be configured for different mail servers or identities. Password handling supports several methods: plaintext (not recommended), passwordeval to run a command (e.g., password manager), or system keyring integration. TLS is supported via STARTTLS or direct TLS connection. Certificate verification can be configured to use system CA certificates or specific files. As a sendmail replacement, msmtp can be symlinked to /usr/sbin/sendmail, making it the default mail transport for the system. Many applications use sendmail for outgoing mail. Integration with mutt, git, and other tools is straightforward - they just need to know the sendmail path or can use msmtp directly.

参数

-a _ACCOUNT_, --account _ACCOUNT_
Use specified account.
-f _ADDRESS_, --from _ADDRESS_
Set From address.
-C _FILE_, --file _FILE_
Use configuration file.
--serverinfo
Print server information.
-P, --pretend
Print configuration, don't send.
--configure _ACCOUNT_
Show account configuration.
-d, --debug
Debug mode.
-t, --read-recipients
Read recipients from message.
-X _FILE_, --logfile _FILE_
Log to file.
--tls
Use TLS encryption.
--tls-starttls
Use STARTTLS.
--host _HOST_
SMTP server host.
--port _PORT_
SMTP server port.
--user _USER_
Authentication username.
--passwordeval _CMD_
Get password from command.

FAQ

What is the msmtp command used for?

msmtp is a lightweight SMTP client for sending email from the command line. It works as a sendmail replacement, enabling scripts and applications to send mail through external SMTP servers. Configuration in ~/.msmtprc defines accounts with server settings, authentication, and TLS options. Multiple accounts can be configured for different mail servers or identities. Password handling supports several methods: plaintext (not recommended), passwordeval to run a command (e.g., password manager), or system keyring integration. TLS is supported via STARTTLS or direct TLS connection. Certificate verification can be configured to use system CA certificates or specific files. As a sendmail replacement, msmtp can be symlinked to /usr/sbin/sendmail, making it the default mail transport for the system. Many applications use sendmail for outgoing mail. Integration with mutt, git, and other tools is straightforward - they just need to know the sendmail path or can use msmtp directly.

How do I run a basic msmtp example?

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

What does -a _ACCOUNT_, --account _ACCOUNT_ do in msmtp?

Use specified account.