centos7 send mail using the mailx

When a server needs to regularly send messages to your mailbox, a mail service is very important, is to achieve the following main mailx, mainly use

1. Install mailx

1
yum  install  mailx -y

2. Use the configuration file only one is /etc/mail.rc, /etc/mail.rc can use an external SMTP server by modifying the configuration file, easily linux mail function.

1
2
3
4
set [email protected]                                            qq邮箱或者其他邮箱
set smtp=smtp.qq.com                                            smtp地址  
set [email protected]                                  
set smtp-auth-password=nibpgbkksmlbbabe                         注意:目前大部分的外部邮件服务使用第三方客户端时,都需要使用授权码,上面的smtp-auth-password使用的就是授权码,而不是邮件帐号的密码。具体操作在最后有附图    

So far, if not a cloud host, been able to achieve send mail. If the cloud host, you need the following actions

First, the configuration using the SMTP mail mailx:
1, the installation mailx; directly yum install mailx -y herein can be installed;
2, /etc/mail.rc in the configuration file, the following entries in the final surface:

1
2
3
4
5
set from= "[email protected]"
set smtp=smtp.126.com
set smtp-auth-user=xxx
set smtp-auth-password=邮箱密码
set smtp-auth=login 

Configuration is very simple, there is not much to say, there are two points to note:
1, the need to open the SMTP mailbox function, open the mailbox of each method are similar;
2, now most use SMTP mail will let you start an authorization code instead of the mailbox password
specific to individual mailbox to open the way authorization code can be directly Baidu;
test whether sent successfully:
mailx -s "mailbox test" [email protected] <message_file test message, if successful, will receive an e-mail inbox immediately, If no, then later on you can see the error shell interface; the above configuration is simple to use SMTP port 25 to send mail function, under normal circumstances we use this is enough, this approach also many online configuration instructions, there will no longer waste time, let's talk about focus, send messages using TSL; I said earlier, Ali cloud the 25 ports closed, re-opened to apply too much trouble, so he thought of using TSL way around E-mail through the port 25; the TSL is using SSL encrypted manner, or to send the message using another port 465, most of the now Mailbox supports SSL, SSL specific port address may be checked Baidu herein is subject mailbox 126, mailbox 126 or 994 using the port 465; the following is a detailed configuration: 1, software requirements: openssl, mailx 12.0 above; 2. Since the use of the SSL protocol, of course, is to have the certificates, the following is an operation of obtaining a certificate;

1
2
3
4
mkdir -p /root/ .certs/
echo -n | openssl s_client -connect smtp.126.com:465 | sed - ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs /qq .crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs /qq .crt
certutil -L -d /root/ .certs<br><br>若需要qq的ssl  只需把第二条命令中的smtp.xxx.com:465  给替换了就行

According to the above operation, as long as no error is normal, we will see several certificate file in /root/.certs Next, the operation was successful; as to why

To do this, do not ask me, I am also a big God COPY way; interested can refer to the article links the last great God;

3, certificate configuration Well, here we're going to configure mail.rc configuration files, and the beginning of a different, here we need to configure and TSL related things

1
2
3
4
5
6
7
set smtp=smtps: //smtp .126.com:465
set smtp-auth-password=你的授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config- dir = /root/ .certs

In fact, on more than a few configuration front stmp added stmps: // protocol type is specified, followed by the port number;

Start ssl protocol, ssl certificate directory specified below, it is so.
After configuring OK, test sending mail;
test can receive mail on OK, explain to send no problem, what is being given as to the specific occur, it can Google based on the content being given;
I am here when sending e-mail will prompt a certificate is not trusted the problem, because they do not affect the normal send a message, so they chose to ignore;

Issue a certificate of no confidence, you need to enter the directory to store certificates, execution

1
cd  /root/ .certs
1
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
1
2
最后显示
Notice: Trust flag u is set automatically if the private key is present.<em id = "__mceDel" > < /em >

 Behind the cloud host implementation      Reprinted from flute

There are three ways to send mail

  • Command line:  mail -s "theme" addressee, press Enter after typing Ctrl+Dsend a message.
  • Pipeline operators: echo "mail main content" | mail -s "theme" addressee
  • File contents as message content: mail -s "theme" addressee < /tmp/t.txt

thme mail title, addressee recipient address

 

 

 

 

qq mailbox open smtp

163 E-mail

 

 

 

 

https://www.cnblogs.com/liutao97/p/8387244.html

When a server needs to regularly send messages to your mailbox, a mail service is very important, is to achieve the following main mailx, mainly use

1. Install mailx

1
yum  install  mailx -y

2. Use the configuration file only one is /etc/mail.rc, /etc/mail.rc can use an external SMTP server by modifying the configuration file, easily linux mail function.

1
2
3
4
set [email protected]                                            qq邮箱或者其他邮箱
set smtp=smtp.qq.com                                            smtp地址  
set [email protected]                                  
set smtp-auth-password=nibpgbkksmlbbabe                         注意:目前大部分的外部邮件服务使用第三方客户端时,都需要使用授权码,上面的smtp-auth-password使用的就是授权码,而不是邮件帐号的密码。具体操作在最后有附图    

So far, if not a cloud host, been able to achieve send mail. If the cloud host, you need the following actions

一、配置mailx使用SMTP发送邮件:
1、安装mailx;这里直接使用yum install mailx -y 进行安装即可;
2、在/etc/mail.rc配置文件中,在最后面输入以下内容:

1
2
3
4
5
set from= "[email protected]"
set smtp=smtp.126.com
set smtp-auth-user=xxx
set smtp-auth-password=邮箱密码
set smtp-auth=login 

配置都很简单,这里就不多说了,有两点需要注意的:
1、邮箱需要开启SMTP功能,每个邮箱的开启方法都大同小异;
2、现在大部分邮箱使用SMTP会让你启动一个授权码来代替邮箱密码
具体各个邮箱开启授权码的方式可以直接百度;
测试是否发送成功:
mailx -s "邮箱测试" [email protected] < message_file 测试邮件一旦成功,收件箱会马上收到邮件,如果没有收到,则等一会可以看到shell界面的错误提示; 上面配置的是简单的使用25端口的SMTP发送邮件的功能,一般情况下我们使用这个就足够了,这个办法 在网上也很多配置说明,这里就不再浪费时间了,下面我们讲重点,使用TSL发送邮件; 前面说了,阿里云把25端口封了,去申请解封也比较麻烦,于是就想到了用TSL方式,绕过25端口发送邮件; TSL也就是使用SSL加密的方式,使用465或者其他端口来发送邮件,现在大部分邮箱都支持SSL,具体SSL的端口 地址,也可以查百度,这里是以126邮箱为准,126邮箱使用的是465或者994端口; 下面是详细的配置过程: 1、软件要求:openssl、mailx 12.0以上; 2、既然使用的是SSL协议,那当然是要有证书的了,下面是获取证书的操作;

1
2
3
4
mkdir -p /root/ .certs/
echo -n | openssl s_client -connect smtp.126.com:465 | sed - ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs /qq .crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs /qq .crt
certutil -L -d /root/ .certs<br><br>若需要qq的ssl  只需把第二条命令中的smtp.xxx.com:465  给替换了就行

按照上面操作,只要不报错,就是正常的,我们会在/root/.certs下面看到几个证书文件,说明操作成功了;至于为什么

要这么做,不要问我,我也是COPY大神的办法;有兴趣的可以参考最后大神的文章链接;

3、证书配置好了,下面我们就要来配置mail.rc配置文件了,和最开始的不同,这里我们就需要配置和TSL相关的东西了

1
2
3
4
5
6
7
set smtp=smtps: //smtp .126.com:465
set smtp-auth-password=你的授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config- dir = /root/ .certs

其实就多了几个配置stmp前面加了stmps://指定协议类型,后面加上端口号;

启动ssl协议 ,下面指定ssl证书所在目录,就这样。
配置OK了之后,测试发送邮件;
测试能收到邮件就OK,说明发送没问题,至于具体会出现什么报错,可以根据报错的内容进行谷歌;
我这里在发送邮件的时候会提示一个证书不信任的问题,因为不影响正常发送邮件,所以选择忽略;

证书不信任的问题,需要进入存放证书的目录,执行

1
cd  /root/ .certs
1
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
1
2
最后显示
Notice: Trust flag u is set automatically if the private key is present.<em id = "__mceDel" > < /em >

 后面云主机实现方法      转载自笛声

使用三种方式发送邮件

  • 命令行: mail -s "theme" addressee,回车后输入内容按Ctrl+D发送邮件.
  • 管道符: echo "mail main content" | mail -s "theme" addressee
  • 文件内容作为邮件内容: mail -s "theme" addressee < /tmp/t.txt

thme是邮件标题,addressee收件人地址

 

 

 

 

qq邮箱开启smtp

163邮箱

 

 

 

 

https://www.cnblogs.com/liutao97/p/8387244.html

Guess you like

Origin www.cnblogs.com/seasonzone/p/11265162.html