`
can_do
  • 浏览: 248622 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

【Do家】Liux下通过mail发送邮件

阅读更多
1、首先,检查是否安装mail命令,如果没有请按以下命令安装
# yum install sendmail
# yum install mailx –y
# yum update libreport-plugin-mailx => yum install libreport-plugin-mailx
注意:此处如果不是更新,就采用安装命令
# yum -y install sharutils
# yum install mutt

2、确认命令都安装ok
# mail --help
mail: illegal option -- -
Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users

3、设置postfix限制规则
# vim /etc/postfix/main.cf
添加如下设置,无则添加,有则修改
//////////////begin///////////////
mynetworks = 127.0.0.1,localhost,172.60.1.0/24
smtpd_sender_restrictions =
        permit_mynetworks,
        reject_sender_login_mismatch,
        reject_authenticated_sender_login_mismatch,
        reject_unauthenticated_sender_login_mismatch
///////////////end//////////////

通过命令postfix加载配置以生效
# postfix reload
postfix/postfix-script: refreshing the Postfix mail system

4、配置发送邮箱账号信息
# vim /etc/mail.rc
文件尾部追加以下配置信息
//////////begin////////
# append for sending mail in individual manner
set from=youraccount@tom.com

set smtp=smtp://smtp.tom.com

set smtp-auth-user=youraccount@tom.com

set smtp-auth-password=<yourpassword>

set smtp-auth=login
//////////end//////////

注意:
1> 属性smtp配置值务必为带协议的写法,不走SSL,采用smtp://smtp.tom.com;走SSL,采用smtps://smtp.tom.com;
   如果port自定义了,也需要配置上;smtps://smtp.tom.com:xxx
2> 属性smtp-auth-user配置值务必为邮箱账号全称写法,比如:youraccount@tom.com,而不是youraccount;

5、通过mail发送邮件
1> 文件内容来自文件
# touch /usr/mail.txt
# echo "how are you?" >> /usr/mail.txt
2> 执行发送命令
# mail -s "System Monitor Log" otheruser@baidu.com  < /usr/mail.txt

6、如果采用SSL发送邮件,需要生成和配置证书
1> 通过openssl生成证书
# mkdir -p /root/.certs

# echo -n | openssl s_client -connect smtp.tom.com:xxx | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt

certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i 163.crt

certutil -L -d /root/.certs
2> /etc/mail.rc中增加引用证书的属性
//////////begin///////
set ssl-verify=ignore

set nss-config-dir=/root/.certs
//////////end//////////

【小结】
1> 如果提示错误Sender address rejected: not owned by user,则优先考虑/etc/postfix/main.cf中规则的设置,将当前发邮件服务器的出网内网ip加到规则中;
2> 如果提示Wrong Receive Channel,则优先考虑/etc/mail.rc中配置信息smtp是否写别
3> 如果提示invalid password,则优先考虑/etc/mail.rc中配置信息smtp-auth-user或者smtp-auth-password是否写别了;
2> 如果提示Sender address rejected: not owned by user zhanglefan@tom.com,也需要考虑/etc/mail.rc中用户配置from是否正确?

【温馨提示】
如果您觉得满意,可以选择支持下,您的支持是我最大的动力:

分享到:
评论

相关推荐

    linux下python使用sendmail发送邮件

    使用linux下的sendmail程序来发送邮件,利用popen函数(python docs关于popen函数)可以直接调用linux系统程序,需要指定程序所在的位置。 python代码: #!/usr/bin/python # -*- coding: UTF-8 -*- #Author: ...

    在linux系统下ftp的配置与实现.do

    在linux系统下ftp的配置与实现.do

    在linux中实现一个命令执行程序doit

    在linux中实现一个命令执行程序doit,它执行命令行参数中的命令,之后统计 1)命令执行占用的CPU时间(包括用户态和系统态时间,以毫秒为单位), 2)命令执行的时间, 3)进程被抢占的次数, 4)进程主动放弃CPU的...

    linux内核 do_fork 函数源代码浅析

    linux内核 do_fork 函数源代码浅析。 经典讲解!

    51CTO下载-自己的E-mail发送接收客户端_分享C#项目开发案例.do

    51CTO下载-自己的E-mail发送接收客户端_分享C#项目开发案例.do

    linux C编程实战

     1.5 Linux下程序的开发环境和开发过程   1.6 习题   第2章 C编程基础、Vi和Emacs编辑器   2.1 C程序的结构   2.2 C语言的基本数据类型   2.2.1 整型   2.2.2 浮点型   2.2.3 字符型   2.3...

    PHP实现在windows下配置sendmail并通过mail()函数发送邮件的方法

    本文实例讲述了PHP实现在windows下配置sendmail并通过mail()函数发送邮件的方法。分享给大家供大家参考,具体如下: 1、php mail()函数在windows不能用,需要安装sendmail。 2、从http://glob.com.au/sendmail/ 下载...

    laravel邮件发送的实现代码示例

    laravel自带SwiftMailer库,集成了多种邮件API,可以很方便的实现邮件的发送。在本教程中使用到的是SMTP(Simple Message Transfer Protocol)简单邮件传输协议,通常理解为邮件发送服务器。 以126邮箱为例 使用126...

    Linux智能家庭自动化

    Do you want to do these things without an expensive off-the-shelf kit? In Smart Home Automation with Linux, Steven Goodwin will show you how a house can be fully controlled by its occupants, all ...

    linux 远程控制windows系统下的程序(三种方法)

    有时候我们需要通过在linux上远程运行windows系统上的程序。 方法一: 通过python中的 winrm模块,前提条件,先提前设置好winrm服务。如何设置请自行百度,winRM服务是windows server下PowerShell的远程管理服务。...

    Linux下利用unzip命令如何解压多个文件详解

    linux中提示没有unzip命令解决方法 ...Linux下直接使用unzip *.zip解压多个文件会报错 可以使用unzip '*.zip'或者 unzip *.zip或者unzip \*.zip命令 或者使用for z in *.zip; do unzip $z; done执

    dopi:嵌入式Linux应用程序框架

    dopi linux开发框架计划,致力于实现一套基于Linux的嵌入式开发集成接口 原始码获取 git clone https://github.com/cijliu/dopi.git cd dopi 构建系统 编译前需要确认已经安装了芯片的工具链,例如,海思HI3516EV...

    Linux内核中的异常处理机制分析

    分析了Linux内核中的异常处理机制

    RS Linux Recovery 1.8 Multilingual.rar

    Do you want to perform data recovery from an ext4 partition from an external hard drive? RS Linux Recovery specially designed to work with file systems Ext2/3/4, ReiserFS, XFS, UFS. The program ...

    linux下C实现的哈希表

    用C实现的哈希表 int hash_insert(Hash* * hp,int data)//返回0... do { num=(num+i*i); i++; }while(((*hp)-&gt;pNode[num]).data!=8888); ((*hp)-&gt;pNode[num]).data=data; } ((*hp)-&gt;num)++; return 0; }

    Linux command introduction.

    command line to tell a Linux system what to do. Here’s an example command that counts lines of text in a file, myfle: wc -l myfile We’ll cover the most important Linux commands for the aver‐ age ...

    react-mail-component:使用React组件在Node js上发送电子邮件!

    React邮件组件 该项目的目的是展示节点js中和用法。 Wich在可重用性方面带来了很多好处,在完成副项目后,在公司上成功实现了它,带来了很多好处,这是开发人员在发送电子邮件... "title" : "Título do E-mail", "to

    Linux期末考试(题多 有点难度)

    Linux文件系统通过把i节点和文件名进行连接,当需要读取该文件时,文件系统在当前目录表中查找该文件名对应的项,由此得到该文件相........ root@xxx:#crontab prgx;在每日早晨8:00之前开机后即可自动启动crontab。...

    jdk-8u201-linux-64.tar.zip

    linux环境下标准jdk8安装包linux环境下标准jdk8安装包linux环境下标准jdk8安装包linux环境下标准jdk8安装包linux环境下标准jdk8安装包linux环境下标准jdk8安装包

Global site tag (gtag.js) - Google Analytics