mailx

最後更新: 2019-08-19

 

目錄

  • CLI UI 看信
  • CLI 出信
  • smtp variable

 


CLI UI 看信

 

Install

yum install mailx             # On C8 = Heirloom mailx 12.5

apt-get install s-nail        # On D8 s-nail (即係 Centos 的 mailx) / mailutils(Default) / bsd-mailx

update-alternatives --config mailx

Usage

  • s[ave]
  • C[opy]
  • d[elete]
  • m[ail]
  • r[eply] [msglist]

 


CLI 出信

 

# Heirloom mailx

mail [-a attachment] [-b bcc-addr] [-c cc-addr] [-r from-addr] [-s subject] to-addr [to-addr2] ...

Opts

  • -s subject      # be careful to quote subjects containing spaces !
  • -a file            # Attach the given file to the message
  • -r address      # Sets the From address
  • -c address     # Send carbon copies to list of users

i.e.

echo "my msg" | mail -s"Server RAID status" you@yourdomain

uuencode file.txt | mail -s"Server RAID status" you@yourdomain

 


smtp variable

 

-S variable[=value]

Normally, mailx invokes sendmail(8) directly to transfer messages.  

If the smtp variable is set, a SMTP connection to the server specified by the value of this variable is used instead.  

 

i.e.

echo "message" | mailx -S smtp=localhost:10025 -s "subject line" -v [email protected]

 


重發 EML

 

-t

The message to be sent is expected to contain a message header with `To:', `Cc:', or `Bcc:' fields giving its recipients

Recipients specified on the command line are ignored.

# -v     # Verbose mode

cat 1.eml | mailx -t -S smtp=localhost:10025 -v

 


mailutils or bsd-mailx

 

Which do you use mailutils or bsd-mailx ?

$ ls -l /etc/alternatives/mail

If the mail command of mailutils, you can specify the sender in the -r option.

$ mail -r [email protected] [email protected]

If the mail command of bsd-mailx, $myorigin setting is enabled.

 


 

Creative Commons license icon Creative Commons license icon