shell postfix测试 邮件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35744460/article/details/89314577

启动

systemctl start postfix.service

测试

命令帮助
[root@spark001 ~]# 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

163邮箱配置

echo -n | openssl s_client -connect smtp.163.com:465 | 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 -L -d /root/.certs
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i 163.crt

标题配置mail.rc

vi /etc/mail.rc

set [email protected]
set smtp=smtp.163.com
set [email protected]
#授权码
set smtp-auth-password=xxxxxxxxx
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs

发邮件不带附件

echo "hello " | mail -s "问候" [email protected]

发邮件带附件

echo "邮件测试test.log" | mailx -a test.log -s "附件" [email protected] 

发送html表格

需要在头部设置Content-Type: text/html

cat mail.html | mailx -s “$(echo -e “subject\nContent-Type: text/html; charset=utf-8”)” [email protected]

mail.html

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style type="text/css">

        table{
			border-collapse: collapse;
		}
		table,th,td{
			border:1px,solid,black;
		}

</style>
<body>
<table border ="1">
	<thead>
		<tr>
			<th>DATABASE</th>
			<th>TABLE</th>
			<th>COUNT</th>
			<th>HBASE-SCHEMA</th>
			<th>TABLE</th>
			<th>COUNT</th>
			<th>C_TIME</th>
		
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>OMS</td>
			<td>OMS_T10</td>
			<td>10000</td>
			<td>DW</td>
			<td>OMS_T10</td>
			<td>10000</td>
			<td>20190412000001</td>
		</tr>
		<tr bgcolor="#FF0000">
			<td>OMS</td>
			<td>OMS_T10</td>
			<td>30000</td>
			<td>DW</td>
			<td>OMS_T10</td>
			<td>29000</td>
			<td>20190412000002</td>
		</tr>
	</tbody>
</table>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_35744460/article/details/89314577