Centos 系统使用mailx发送邮件

2019-04-02 0 By admin

Centos6 系统中默认安装的是 Sendmail 邮件服务,自带 mail 邮件发送和接受工具。在Centos7 系统中默认安装的是 Postfix 邮件服务,并没有安装邮件发送和接受的命令工具。所以我们如果想在Centos7 系统中发送邮件的话,需要自行安装一下邮件发送工具,如mailx。

一、mailx 工具使用介绍

-s subject 主题
-a file 附件Attach the given file to the message.
-r address 发件人Sets the From address.
-c address 抄送人Send carbon copies to list of users.
-b address 密送 Send blind carbon copies to list.

二、发送格式

mailx -s subject -r sender.163.com receiver.163.com < mail_content
mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . .
mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f [name]
mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user]

多个收件人之间使用逗号隔开。

三、发送邮件和查看邮件

发送邮件
使用mailx 并结合相应的参数,可以将邮件发送至一个或者多个收件人。
The user is then expected to type in his message, followed by an ‘control-D’ at the beginning of a line. The section below Replying to or originating mail, describes some features of mailx available to help when composing letters.
查看邮件
在正常使用 mailx 不设置任何参数,会检查用户在邮局外的邮件,然后打印出找到的每封邮件的一行标题。