跳至主要内容

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...

MechanicalSoup

用于自动与网站交互的 Python 库。 MechanicalSoup 自动存储和发送 cookie,跟踪重定向,并且可以跟踪链接和提交表单。 它不执行 JavaScript。 https://github.com/MechanicalSoup/MechanicalSoup https://mechanicalsoup.readthedocs.io/en/stable/index.html https://realpython.com/python-web-scraping-practical-introduction/ pip show Mechanicalsoup 找到模块的安装位置 https://stackoverflow.com/questions/54352162/download-file-with-mechanicalsoup # Install dependencies # pip install requests # pip install BeautifulSoup4 # pip install MechanicalSoup # Import libraries import mechanicalsoup import urllib.request import requests from bs4 import BeautifulSoup import re # Create a browser object that can collect cookies browser = mechanicalsoup.StatefulBrowser() browser.open("https://www.ons.gov.uk/economy/grossdomesticproductgdp/timeseries/l2kq/qna") browser.download_link(link_text=".xls",file="D:/ONS_Data.xls" )

安装和卸载软件(msi\exe)

如何判断一个软件是64位的还是32位的? 情况1、 未安装--右键安装程序查看属性,兼容性,勾选兼容模式查看最低适配是vista的是64位,反之32位, 不太准确 情况2、 已安装--运行软件,64位操作系统打开任务管理器看进程后缀名,带*32就是32位,反之64位 https://www.joci.net/xxbk/126251/ FileMon 和 Regmon 不再可供下载。从Windows 2000 SP4,Windows XP SP2,Windows Server 2003 SP1和Windows Vista开始的Windows版本上,它们已被 Process Monitor 取代 https://adamtheautomator.com/procmon/ Process Monitor 是Windows的高级监视工具,它显示实时文件系统,注册表和进程/线程活动。 它结合了两个旧的Sysinternals实用程序 Filemon 和  Regmon的功能 ,并添加了广泛的增强功能列表,包括丰富的和非破坏性的过滤,全面的事件属性(例如会话ID和用户名),可靠的过程信息,带有集成符号的完整线程堆栈支持每个操作,同时记录到文件等。 它独特的强大功能将使Process Monitor成为您的系统故障排除和恶意软件搜索工具包中的核心实用程序。 https://wikileaks.org/ciav7p1/cms/page_42991626.html HKLM\Software\Microsoft\Cryptography\MachineGuid Machine GUID/Cryptography GUID---该密钥通常用作机器的唯一标识符。它也已用于将两台计算机链接在一起-在某些情况下,计算机GUID是与设备(MP3播放器等)一起传递的。 Machine GUID不是唯一 https://docs.microsoft.com/zh-cn/windows/win32/properties/props-system-identity-uniqueid?redirectedfrom=MSDN UniqueID才是唯一 注册表 是存储系统和应用程序的设置信息 打开注册表的方式很简单:cmd中输入regedit 卸载路径只有一个 已安装32位的程序,如果是系统是32位...