本文简单整理了一下如何在Linux服务器上安装、配置SendMail发送邮件的步骤,此文不是配置邮件服务器,具体测试环境为CentOS Linux release 7.2.1511 (Core) ,如遇特殊平台有所差别,请以实际情况为准则。

Linux 系统版本查看

检查、了解系统版本信息,主要是如果使用rpm安装时,需要下载合适的版本。

[root@mylnx06 ~]# more /etc/redhat-release 

CentOS Linux release 7.2.1511 (Core)

 

检查是否安装sendmail组件

如下所示,该服务器上并没有安装sendmail的相关组件。那么我们直接使用yum安装sendmail组件即可。

[root@mylnx06 ~]# rpm -qa | grep sendmail

 

 

 

[root@mylnx06 ~]# yum list sendmail

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * epel: ftp.cuhk.edu.hk

Available Packages

sendmail.x86_64                                       8.14.7-4.el7                    base

使用yum安装sendmail组件,当然你可以使用其它方式安装,此处不做展开介绍。

[root@mylnx06 ~]# yum install sendmail.x86_64 

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * epel: ftp.cuhk.edu.hk

Resolving Dependencies

--> Running transaction check

---> Package sendmail.x86_64 0:8.14.7-4.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

========================================================================================================================

 Package                     Arch                      Version                            Repository               Size

========================================================================================================================

Installing:

 sendmail                    x86_64                    8.14.7-4.el7                       base                    722 k

 

Transaction Summary

========================================================================================================================

Install  1 Package

 

Total download size: 722 k

Installed size: 1.6 M

Is this ok [y/d/N]: y

Downloading packages:

sendmail-8.14.7-4.el7.x86_64.rpm                                                                 | 722 kB  00:00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : sendmail-8.14.7-4.el7.x86_64                                                                         1/1 

  Verifying  : sendmail-8.14.7-4.el7.x86_64                                                                         1/1 

 

Installed:

  sendmail.x86_64 0:8.14.7-4.el7                                                                                        

 

Complete!

[root@mylnx06 ~]# 

 

编辑/etc/aliases文件

Sendmail有一个非常实用的功能,就是为每个账号取别名(Aliase) 会使用一个在 /etc/aliases 中的档案做使用者名称转换的动作。 所以这个配置文件是可配也可以不配,具体视你的需求而定。

[root@mylnx06 ~]# vi /etc/aliases

#

#  Aliases in this file will NOT be expanded in the header from

#  Mail, but WILL be visible over networks or from /bin/mail.

#

#       >>>>>>>>>>      The program "newaliases" must be run after

#       >> NOTE >>      this file is updated for any changes to

#       >>>>>>>>>>      show through to sendmail.

#

 

# Basic system aliases -- these MUST be present.

mailer-daemon:  postmaster

postmaster:     root

 

# General redirections for pseudo accounts.

bin:            root

daemon:         root

adm:            root

lp:             root

sync:           root

shutdown:       root

halt:           root

mail:           root

news:           root

uucp:           root

operator:       root

games:          root

gopher:         root

ftp:            root

nobody:         root

radiusd:        root

nut:            root

dbus:           root

vcsa:           root

canna:          root

wnn:            root

rpm:            root

nscd:           root

pcap:           root

apache:         root

webalizer:      root

dovecot:        root

fax:            root

quagga:         root

radvd:          root

pvm:            root

amandabackup:           root

privoxy:        root

ident:          root

named:          root

xfs:            root

gdm:            root

mailnull:       root

postgres:       root

sshd:           root

smmsp:          root

postfix:        root

netdump:        root

ldap:           root

squid:          root

ntp:            root

mysql:          root

desktop:        root

rpcuser:        root

rpc:            root

nfsnobody:      root

 

ingres:         root

system:         root

toor:           root

manager:        root

dumper:         root

abuse:          root

 

newsadm:        news

newsadmin:      news

usenet:         news

ftpadm:         ftp

ftpadmin:       ftp

ftp-adm:        ftp

ftp-admin:      ftp

www:            webmaster

webmaster:      root

noc:            root

security:       root

hostmaster:     root

info:           postmaster

marketing:      postmaster

sales:          postmaster

support:        postmaster

 

 

# trap decode to catch security attacks

decode:         root

 

# Person who should get root's mail

#root:          marc

如下截图所示,如果我配置别名为root的,配置接收邮件(下面邮件仅仅是一个模板而已)

 

修改配置文件sendmail.cf

修改/etc/mail/sendmail.cf 添加对应的DS, DS后面为邮件服务器的IP地址。根据实际具体情况配置。其实这个配置文件,如果需要,还有蛮多需要配置、细化的地方,此处只讲述最简单的配置。

# host/domain names ending with a token in class P are canonical

CP.

 

# "Smart" relay host (may be null)

DS[xxx.xxx.xxx.xxx]

 

 

# operators that cannot be in local usernames (i.e., network indicators)

CO @ % !

 

# a class with just dot (for identifying canonical names)

 

重启sendmail服务

[root@mylnx06 ~]# service sendmail status

Redirecting to /bin/systemctl status  sendmail.service

● sendmail.service - Sendmail Mail Transport Agent

   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)

   Active: inactive (dead)

 

Feb 22 10:29:45 azlnx06 systemd[1]: Stopped Sendmail Mail Transport Agent.

 

 

[root@mylnx06 ~]# service sendmail start

Redirecting to /bin/systemctl start  sendmail.service

[root@mylnx06 ~]# service sendmail status

Redirecting to /bin/systemctl status  sendmail.service

● sendmail.service - Sendmail Mail Transport Agent

   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)

   Active: active (running) since Wed 2017-02-22 10:42:02 HKT; 5s ago

  Process: 46129 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)

  Process: 46116 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)

  Process: 46115 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)

 Main PID: 46131 (sendmail)

   CGroup: /system.slice/sendmail.service

           └─46131 sendmail: accepting connections

 

Feb 22 10:42:02 azlnx06 systemd[1]: Starting Sendmail Mail Transport Agent...

Feb 22 10:42:02 azlnx06 sendmail[46124]: alias database /etc/aliases rebuilt by root

Feb 22 10:42:02 azlnx06 sendmail[46124]: /etc/aliases: 77 aliases, longest 17 bytes, 792 bytes total

Feb 22 10:42:02 azlnx06 sendmail[46131]: starting daemon (8.14.7): SMTP+queueing@01:00:00

Feb 22 10:42:02 azlnx06 systemd[1]: PID file /run/sendmail.pid not readable (yet?) after start.

Feb 22 10:42:02 azlnx06 systemd[1]: Started Sendmail Mail Transport Agent

 

测试邮件服务

如下所示,使用mail命令测试能否成功收到邮件。如果成功,表示前面配置OK, 如果没有收到邮件,则必须检查日志,然后根据具体错误信息诊断问题。

 

[root@mylnx06 ~]# cat > test.txt

it is only test

^Z

[1]+  Stopped                 cat > test.txt

[root@mylnx06 ~]# mail -s "test" konglb@xxxx.com < test.txt 

[root@mylnx06 ~]# 

 

 

[azrlnx06azlnx06 ~]$ echo 'it is only a test' | mail -s "test eamil"  konglb@xxxx.com

[azrlnx06@azlnx06 ~]$ 

Linux简单配置SendMail发送邮件的更多相关文章

  1. linux简单配置

    lsof -i lsof -i:211.判断apache查找httpd路径: ps aux | grep httpd 结果:  /usr/local/apache/bin/httpd /usr/loc ...

  2. linux安装配置sendmail实现邮件发送

    sendmail配置 yum -y update sendmail sendmail-cf SendMail相关目录1. 设定档目录:/etc/mail2. 记录档:/var/log/maillog3 ...

  3. Linux基础命令---sendmail发送邮件

    sendmail sendmail是postfix中的一个发送邮件的代理程序,它负责发送邮件到远程服务器,并且可以接收邮件.sendmail在发送邮件的时候,默认从标砖输入读取内容,以".& ...

  4. Linux系统下sendmail发送邮件失败的问题

         问题是:安装完sendmail,启动服务后,发送邮件第一次发送成功,后面再次无论怎么发送都不行,换邮箱也不行.在确认我的邮件发送格式正确无误后,想到查看邮件发送日志: [root@backu ...

  5. Linux下使用sendmail发送邮件

    现在每天需要将统计数据发送给指定的人员. 使用原始手工的方式每天发送很麻烦,于是想改成一个定时任务,让服务器自动发送. 技术告诉我说他有写过sendmail的一个脚本. 我尝试使用了一下,发现 ser ...

  6. wamp配置sendmail发送邮件

    下载 sendmail ( 地址: http://www.glob.com.au/sendmail/sendmail.zip ) [PHP.ini 配置] [mail function]; For W ...

  7. Linux中使用sendmail发送邮件,指定任意邮件发送人

    一.使用任意发件人发送邮件 echo .com -s .com 其中s表示主题.

  8. dokuwiki 配置 sendmail 邮件发送

    dokuwiki 发送邮件有2种方式: 一是直接使用 PHP 自带发送功能,需要配置 PHP.ini 文件, 我没试过,可参考官网 https://www.dokuwiki.org/tips:mail ...

  9. 自学Zabbix3.10.2.1 linux如何配置使用sendEmail发送邮件

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix3.10.2.1 linux如何配置使用sendEmail发送邮件 sendEma ...

随机推荐

  1. ASP.NET 一个数据访问层的封装

    刚通过开通写博客的申请,向博客园的大佬致敬,由于一直以来都在网上搜索大家的思想,也有翻遍整个百度都有的找不到的时候,作为一个网民理应为互联网贡献一点东西. 下面是我工作后受一个师傅的影响对数据库访问层 ...

  2. RSA算法原理——(2)RSA简介及基础数论知识

    上期为大家介绍了目前常见加密算法,相信阅读过的同学们对目前的加密算法也算是有了一个大概的了解.如果你对这些解密算法概念及特点还不是很清晰的话,昌昌非常推荐大家可以看看HTTPS的加密通信原理,因为HT ...

  3. 微信小程序入门(五)

    24.MINA框架讲解 MINA框架架构 25.小程序运行机制 小程序在首次打开的时间会比较长,后续再打开启动会很快,那么小程序是如何启动的呢? 运行机制-启动 冷启动 热启动 热启动:假入用户已经打 ...

  4. BBS论坛(二十)

    20.1.cms添加轮播图后台逻辑代码完成 (1)apps/models.py from exts import db from datetime import datetime class Bann ...

  5. 【java设计模式】(3)---代理模式(案例解析)

    设计模式之代理模式 一.概述 1.什么是代理模式? 解释第一遍:代理模式主要由三个元素共同构成: 1)一个接口,接口中的方法是要真正去实现的. 2)被代理类,实现上述接口,这是真正去执行接口中方法的类 ...

  6. 8分钟学会使用AutoMapper

    一.什么是AutoMapper与为什么用它. 它是一种对象与对象之间的映射器,让AutoMapper有意思的就是在于它提供了一些将类型A映射到类型B这种无聊的实例,只要B遵循AutoMapper已经建 ...

  7. Python:数据可视化pyecharts的使用

    什么是pyecharts? pyecharts 是一个用于生成 Echarts 图表的类库. echarts 是百度开源的一个数据可视化 JS 库,主要用于数据可视化.pyecharts 是一个用于生 ...

  8. 前端笔记之JavaScript(三)关于条件判断语句、循环语句那点事

    一.条件分支语句 条件分支语句,也叫作条件判断语句,就是根据某种条件执行某些语句,不执行某些语句. JS中有三种语法是可以表示条件分支的 1.1 if……else…… 条件分支的主力语法,这个主力语法 ...

  9. 如何学习SpringCloud?(SpringCloud模板)

    前言 对于SpringCloud来说(下面简称SC),现在网上已经有很多教程写的非常详细,因为SC的组件特别多,虽然不是所有组件都需要用到,但是学习的时候我们都需要去学习和了解.所以我想如果再写把每一 ...

  10. 爬虫协议 Tobots

    一.简介 Robots 协议(也称为爬虫协议.机器人协议等)的全称是“网络爬虫排除标准”(Robots Exclusion Protocol),网站通过 Robots 协议告诉搜索引擎哪些页面可以抓取 ...