跳至主要内容

linux 发邮件

https://linuxhint.com/bash_script_send_email/


https://www.linuxtechi.com/install-configure-postfix-mailserver-centos-8/

https://support.itrsgroup.com/hc/en-us/articles/360020253193-Sending-outgoing-notifications-via-SMTP-relay


https://www.mail-tester.com/

https://www.linuxtechi.com/log-email-subject-maillog/

https://community.spiceworks.com/linux?source=navbar-subnav


By default postfix only capture ‘From’ and ‘To’ details in the log file (/var/log/maillog).



如何在CentOS 上安装和配置Postfix邮件服务器

Postfix是免费的开源MTA(邮件传输代理),用于在Linux系统上路由或传递电子邮件

设置:
操作系统:CentOS 7服务器
IP地址:192.168.43.128
主机名:server1.admin.info(确保域名指向服务器的IP)

在继续进行操作之前,还请确保不存在其他MTA(例如Sendmail),因为这将导致与Postfix配置冲突。例如,要删除Sendmail,请运行以下命令
# yum remove sendmail

设置主机名并更新/etc/hosts文件
使用下面的hostnamectl命令在系统上设置主机名
# hostnamectl set-hostname server1.admin.info
# exec bash

此外,您需要在/etc/hosts文件中添加系统的主机名和IP条目
# vi /etc/hosts 
192.168.43.128 server1.admin.info
保存并退出文件

安装Postfix邮件服务器
在验证系统上没有其他MTA正在运行之后,通过执行以下命令安装Postfix
# yum install postfix

启动并启用Postfix服务
成功安装Postfix后,通过运行以下命令启动并启用Postfix服务
# systemctl start postfix
# systemctl enable postfix
要检查Postfix状态,请运行以下systemctl命令
# systemctl status postfix


我们已经验证了Postfix已启动并正在运行。接下来,我们将配置Postfix以将电子邮件本地发送到我们的服务器。

安装mailx电子邮件客户端
在配置Postfix服务器之前,我们需要安装mailx功能,要安装mailx,请运行以下命令
# yum install mailx

配置Postfix邮件服务器
Postfix的配置文件位于/etc/postfix/main.cf中。我们需要对配置文件进行一些更改,因此请使用您喜欢的文本编辑器将其打开。
# sudo vi /etc/postfix/main.cf

更改以下几行
myhostname = server1.admin.info
mydomain = admin.info
myorigin = $mydomain
## Uncomment comment ##
inet_interfaces = all
## Comment ##
#inet_interfaces = localhost
## Change to all ##
inet_protocols = all
## Comment ##
#mydestination = $myhostname, localhost.$mydomain, localhost
## Uncomment ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## Uncomment and add IP range ##
mynetworks = 192.168.43.0/24, 127.0.0.0/8
## Uncomment ##
home_mailbox = Maildir/

校验更改
# cat /etc/postfix/main.cf | grep -Env '^$|#'

完成后,保存并退出配置文件。重新启动后缀服务以使更改生效
# systemctl restart postfix

测试Postfix邮件服务器
测试我们的配置是否有效,首先,创建一个测试用户
# useradd postfixuser 
# passwd postfixuser

接下来,运行以下命令以将电子邮件从beijing本地用户发送给另一个用户“postfixuser ”
# telnet localhost smtp
or
# telnet localhost 25

如果未安装telnet服务,则可以使用以下命令进行安装
# dnf install telnet -y

如前所述运行命令时,应获得如下所示的输出
[root@server1 ~]# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server1.admin.info ESMTP Postfix

以上确认与postfix邮件服务器的连接正常。接下来,键入命令:
# ehlo localhost
输出将是这样的
250-server1.admin.info
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

接下来,运行以橙色突出显示的命令,例如“mail from”,“rcpt to”,data,最后键入quit
mail from:<beijing>
250 2.1.0 Ok
rcpt to:<postfixuser>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello,welcom to my mailserver(Postfix)
.
250 2.0.0 Ok: queued as D1DCA813CE6
quit
221 2.0.0 Bye
Connection closed by foreign host.

完整的telnet命令可以将电子邮件从本地用户“beijing”发送到另一个本地用户“postfixuser”

如果一切都按计划进行,则您应该能够查看在新用户的主目录中发送的电子邮件
[root@server1 new]# ls /home/postfixuser/Maildir/new
1576549565.Vfd04I200a0adM774839.server1.admin.info

要阅读电子邮件,只需使用cat命令,如下所示
# cat /home/postfixuser/Maildir/new/1576549565.Vfd04I200a0adM774839.server1.admin.info

Postfix邮件服务器日志
Postfix邮件服务器邮件日志存储在文件“/var/log/maillog”中,使用以下命令查看实时日志
# tail -f /var/log/maillog

退出用Ctrl+C

保护Postfix邮件服务器
始终建议确保客户端和后缀服务器之间的通信安全,这可以使用SSL证书来实现,这些证书可以来自受信任的权威机构或“自签名”证书。在本教程中,我们将使用openssl命令生成用于后缀的自签名证书
我假设openssl已经安装在您的系统上,如果未安装,请使用以下yum命令
# yum install openssl -y


使用下面的openssl命令生成私钥和CSR(证书签名请求)
# openssl req -nodes -newkey rsa:2048 -keyout mail.key -out mail.csr
Generating a 2048 bit RSA private key
.....................................+++
.....................................................................+++
writing new private key to 'mail.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shang Hai
Locality Name (eg, city) [Default City]:Shang Hai
Organization Name (eg, company) [Default Company Ltd]:IT
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:server1.admin.info
Email Address []:info@admin.info

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

现在,使用以下openssl命令生成自签名证书,
# openssl x509 -req -days 365 -in mail.csr -signkey mail.key -out mail.crt
Signature ok
subject=/C=CN/ST=Shang Hai/L=Shang Hai/O=IT/OU=IT/CN=server1.admin.info/emailAddress=info@admin.info
Getting Private key


现在将私钥和证书文件复制到/etc/postfix目录
# cp mail.key mail.crt /etc/postfix

在后缀配置文件中添加私钥和证书文件的路径
# vi /etc/postfix/main.cf
………
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/mail.crt
smtpd_tls_key_file = /etc/postfix/mail.key
smtpd_tls_security_level = may
………


重新启动postfix服务以使上述更改生效
systemctl restart postfix

让我们尝试使用mailx客户端将电子邮件发送到内部本地域和外部域
发送本地内部电子邮件
# echo "test email" | mailx -s "Test email from Postfix MailServer" -r shanghai@admin.info postfixuser@admin.info
使用以下方法检查并阅读电子邮件
[root@server1 new]# cd /home/postfixuser/Maildir/new/
[root@server1 new]# ll
总用量 20
-rw-------. 1 postfixuser postfixuser  434 12月 17 10:26 1576549565.Vfd04I200a0adM774839.server1.admin.info
-rw-------. 1 postfixuser postfixuser  561 12月 17 10:48 1576550892.Vfd04I200a0aeM465920.server1.admin.info
-rw-r--r--. 1 root        root        1306 12月 17 10:39 mail.crt
-rw-r--r--. 1 root        root        1054 12月 17 10:38 mail.csr
-rw-r--r--. 1 root        root        1704 12月 17 10:38 mail.key
[root@server1 new]# cat 1576550892.Vfd04I200a0aeM465920.server1.admin.info 
Return-Path: <shanghai@admin.info>
X-Original-To: postfixuser@admin.info
Delivered-To: postfixuser@admin.info
Received: by server1.admin.info (Postfix, from userid 0)
        id 60BFC813CE6; Tue, 17 Dec 2019 10:48:12 +0800 (CST)
Date: Tue, 17 Dec 2019 10:48:12 +0800
From: shanghai@admin.info
To: postfixuser@admin.info
Subject: Test email from Postfix MailServer
Message-ID: <5df841ec.OIQwHU4o+XUCrKk0%shanghai@admin.info>
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test email


发送电子邮件到外部域
# echo "External Test email" | mailx -s "Postfix MailServer" -r info@admin.info jk.d@aisino.sh.cn
# echo "External Test email" | mailx -s "Postfix MailServer" -r infomaster@admin.info jk.d@aisino.sh.cn
echo "External Test email" | mailx -s "Postfix MailServer"  jk.d@aisino.sh.cn
注册发QQ邮箱要加白名单,发件人不填则默认为root@admin.info



检查Postfix邮件队列
使用mailq命令列出队列中的邮件
# mailq
Mail queue is empty

# 查看邮件日志
cat /var/log/maillog





评论

此博客中的热门博文

学习地址

清华大学计算机系课程攻略 https://github.com/PKUanonym/REKCARC-TSC-UHT 浙江大学课程攻略共享计划 https://github.com/QSCTech/zju-icicles https://home.unicode.org/ 世界上的每个人都应该能够在手机和电脑上使用自己的语言。 http://codecanyon.net   初次看到这个网站,小伙伴们表示都惊呆了。原来代码也可以放在网上卖的?!! 很多coder上传了各种代码,每个代码都明码标价。看了下销售排行,有的19刀的卖了3万多份,额di神啊。可以看到代码的演示效果,真的很漂亮。代码以php、wordpress主题、Javascript、css为主,偏前台。 https://www.lintcode.com/ 算法学习网站,上去每天刷两道算法题,走遍天下都不怕。 https://www.codecademy.com/ 包含在线编程练习和课程视频 https://www.reddit.com/ 包含有趣的编程挑战题,即使不会写,也可以查看他人的解决方法。 https://ideone.com/ 在线编译器,可运行,可查看代码示例。 http://it-ebooks.info/ 大型电子图书馆,可即时免费下载书籍。 刷题 https://github.com/jackfrued/Python-100-Days https://github.com/kenwoodjw/python_interview_question 面试问题 https://github.com/kenwoodjw/python_interview_question https://www.journaldev.com/15490/python-interview-questions#python-interpreter HTTP 身份验证 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Authentication RESTful 架构详解 https://www.runoob.com/w3cnote/restful-architecture.html https://www.rosettacode.org/wiki/Rosetta_C...

PDF处理

虚拟pdf打印机 pdfFactory  https://fineprint.com PDFCreator  https://www.pdfforge.org 开源 cutepdf https://www.cutepdf.com/index.htm Doro PDF Writer http://www.the-sz.com/products/doro PdfScribe  https://github.com/stchan/PdfScribe/releases pdf阅读器 Sumatra PDF https://www.sumatrapdfreader.org/ 为什么 Python 用于 PDF 处理  如您所知,PDF 处理属于文本分析。 大多数文本分析库或框架仅使用 Python 设计。 这为文本分析提供了优势。 还有一件事,您永远无法在现有的机器学习或自然语言处理框架中直接处理 pdf。 除非他们为此证明了显式接口。 我们必须先将pdf转换为文本。 我们可以使用下述任何库轻松实现这一点。 在线转换pdf Sejda https://www.sejda.com/pdf-editor 每个文档 200 页的免费限制 https://www.pdf2go.com/ https://tools.pdfforge.org/extract-text PDF24 Tools https://tools.pdf24.org/zh/ 免费且易于使用的在线PDF工具 FreeOCR http://www.paperfile.net/ 适用于Windows的免费光学字符识别软件,支持大多数Twain扫描仪的扫描,还可以打开大多数扫描的PDF和多页Tiff图像以及流行的图像文件格式,FreeOCR输出纯文本,可以直接导出为Microsoft Word格式。 不支持中文 wkhtmltopdf 和 wkhtmltoimage 是使用 QT Webkit 渲染引擎将 HTML 渲染为 PDF 和各种图像格式的命令行工具。这些完全“无头”运行,不需要显示或显示服务。 https://wkhtmltopdf.org/ django-wkhtmltopdf 允许 Django 站点输出动态 PDF。它利用 wkhtmltopdf 库,允许您使用您知道...

安卓 之 apk下载、ADB、 scrcpy

Apk下载 下载离线安装apk https://www.apkmirror.com/ 免费和安全的Android APK下载 https://apkpure.com/ 被暴雷,有植入 https://apps.evozi.com/apk-downloader/ 可以将Google Play( https://play.google.com )中的apk文件所在网址直接下载到台式机和设备上 https://f-droid.org/zh_Hans/ F-Droid 是一个 Android 平台上 FOSS(Free and Open Source Software,自由开源软件)的目录,并提供下载安装支持。使用客户端可以更轻松地浏览、安装及跟进设备上的应用更新。 https://gitlab.com/AuroraOSS/AuroraStore Aurora商店 是Google Play商店的非官方FOSS客户,设计典雅。 Aurora商店不仅下载,更新和搜索Play商店等应用 https://github.com/OpenTracksApp/OpenTracks OpenTracks是一款运动跟踪应用程序,完全尊重您的隐私。 Tasker https://tasker.joaoapps.com/ 是一款适用于Android的应用程序,它可以根据用户定义的配置文件中的上下文、可点击或定时的主屏幕小部件来执行任务。它无需root或特殊的主屏幕就能控制Android设备。 AsciiCam AsciiCam可以从您的相机指向的任何位置实时生成ASCII图像。选择黑白,原色或全彩,拍照,并将其作为图像或HTML共享。您还可以在库中创建ASCII版本的图片,并且每次使用标准相机应用程序拍摄照片时,也可以选择自动生成ASCII版本。 AsciiCam是完全免费和开源的。 Apk1安装器 优化微信apk文件接收体验。 微信收到apk文件会加 ".1" 后缀导致打不开,必须自己手动找到文件重命名去掉后缀。 使用本安装器就可以在微信内,潇洒地点击直接打开。甚至可以在安装器内浏览apk1文件历史接收记录。 ADB ADB全名是 Android Debug Bridge,是开发或使用Android时很常用的工具。可以从电脑通过USB连线到Android手机上 https:...