首页 > 系统相关 >Ubuntu下配置sendmail邮件服务器

Ubuntu下配置sendmail邮件服务器

时间:2022-11-23 12:44:30浏览次数:38  
标签:www mail sendmail hoyeong huhy 192.168 Ubuntu 服务器 com

@

目录

环境准备

部署好dns邮件域名

邮件域名 ip
www.hoyeong.com 192.168.200.160
root@huhy:~# host www.hoyeong.com
www.hoyeong.com has address 192.168.200.160

软件环境;

ubuntu22服务端
ubuntu22客户端测试

服务端部署

安装sendmail软件包

apt install -y sendmail

使用sendconfig命令配置

sendmailconfig
#默认直接回车即可
y

#输入n回车,表示不使用默认配置的sendmail,而是自定义
n

#直接回车
ENTER回车

#输入邮件输入域名,2级即可
hoyeong.com

一直回车到底然后会生效配置文件(然后需要等待一会时间)

#然后直接回车即可,默认会重启sendmail
Reload the running sendmail now with the new configuration?

修改主机名为域名

root@huhy:~# vim /etc/hostname
root@huhy:~# cat /etc/hostname
hoyeong.com

修改配置文件

vim /etc/mail/sendmail.mc

将监听范围设置为本机

#127.0.0.1改为0.0.0.0
DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=0.0.0.0')dnl

DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, M=Ea, Addr=0.0.0.0')dnl
vim /etc/mail/local-host-names

hoyeong.com
192.168.200.160

修改access文件,提前备份好习惯

cp /etc/mail/access{,.bak}
cat > /etc/mail/access eof
Connect:hoyeong.com             RELAY
Connect:192.168.200.160         RELAY
eof

在/etc/mail/目录下配置生效

make

重启生效

systemctl restart sendmail

服务端创建两个mail用户,用于测试

root@huhy:~# useradd -m mail1
root@huhy:~# useradd -m mail2
root@huhy:~# passwd mail1
New password:
Retype new password:
passwd: password updated successfully
root@huhy:~# passwd mail2
New password:
Retype new password:
passwd: password updated successfully

客户端测试

首先修改dns为服务端ip

root@slave1:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.200.101/24]
      gateway4: 192.168.200.2
      nameservers:
        addresses: [192.168.200.160,8.8.8.8]
  version: 2
root@slave1:~#

#重启生效
root@slave1:~# netplan apply
root@slave1:~# ping www.hoyeong.com
PING www.hoyeong.com (192.168.200.160) 56(84) bytes of data.
64 bytes from www.hoyeong.com (192.168.200.160): icmp_seq=1 ttl=64 time=0.498 ms
64 bytes from www.hoyeong.com (192.168.200.160): icmp_seq=2 ttl=64 time=0.969 ms
^C
--- www.hoyeong.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1003ms
rtt min/avg/max/mdev = 0.498/0.733/0.969/0.235 ms
root@slave1:~#

ubuntu默认有telnet工具

命令解释;
telnet 邮件域名 25端口

helo 域名(测试是否可以连接)

mail from:"邮件主题"<服务端用户@域名> (邮件发送者)

rcpt to:mail1@域名 (邮件接收者,这里接收者和发送者都为mail1)

data (回车后输入正文)

. (以点结尾)

quit退出

telnet www.hoyeong.com 25

helo www.hoyeong.com


mail from:"Hello mail"<[email protected]>


rcpt to:[email protected]


data
354 Enter mail, end with "." on a line by itself
hello huhy,welcome!!!!
.

quit

ubuntu客户端具体操作如下

root@slave1:~# telnet hoyeong.com 25
Trying ::1...
telnet: Unable to connect to remote host: Connection refused
root@slave1:~# telnet www.hoyeong.com 25
Trying 192.168.200.160...
Connected to www.hoyeong.com.
Escape character is '^]'.
220 huhy ESMTP Sendmail 8.15.2/8.15.2/Debian-22ubuntu3; Tue, 22 Nov 2022 14:08:36 GMT; (No UCE/UBE) logging access from: [192.168.200.101](FAIL)-[192.168.200.101]
helo www.hoyeong.com
250 huhy Hello [192.168.200.101], pleased to meet you
mail from:"Hello mail"<[email protected]>
250 2.1.0 "Hello mail"<[email protected]>... Sender ok
rcpt to:[email protected]
250 2.1.5 [email protected]... Recipient ok
data
354 Enter mail, end with "." on a line by itself
hello huhy,welcome!!!!
.
250 2.0.0 2AME8a4K004428 Message accepted for delivery
quit
221 2.0.0 huhy closing connection
Connection closed by foreign host.
root@slave1:~#

服务端验证查看,安装mailutils工具

apt install -y mailutils

由于是发送到mail1用户,需要登录到mail1

root@huhy:~# su mail1
$ mail
"/var/mail/mail1": 1 message 1 new
>N   1 [email protected]. Tue Nov 22 14:11  10/352
? 1
Return-Path: <[email protected]>
Received: from www.hoyeong.com ([192.168.200.101])
        by huhy (8.15.2/8.15.2/Debian-22ubuntu3) with SMTP id 2AME8a4K004428
        for [email protected]; Tue, 22 Nov 2022 14:10:30 GMT
Date: Tue, 22 Nov 2022 14:08:36 GMT
From: [email protected]
Message-Id: <202211221410.2AME8a4K004428@huhy>

hello huhy,welcome!!!!

?
#使用exit退出

安装pop3协议

达到不登录到服务端服务器,在客户端服务器就可以查看邮件的目的

服务端安装以下软件包

apt install -y dovecot-imapd
apt install -y dovecot-pop3d

修改配置文件

vim /etc/dovecot/dovecot.conf

#解开注释,添加dns地址网段
login_trusted_networks = 192.168.200.0/24

重启服务

systemctl restart dovecot

再次发送邮件验证测试

root@slave1:~# telnet www.hoyeong.com 25
Trying 192.168.200.160...
Connected to www.hoyeong.com.
Escape character is '^]'.
220 huhy ESMTP Sendmail 8.15.2/8.15.2/Debian-22ubuntu3; Tue, 22 Nov 2022 14:33:51 GMT; (No UCE/UBE) logging access from: [192.168.200.101](FAIL)-[192.168.200.101]
helo www.hoyeong.com
250 huhy Hello [192.168.200.101], pleased to meet you
mail from:[email protected]
250 2.1.0 [email protected]... Sender ok
rcpt to:[email protected]
250 2.1.5 [email protected]... Recipient ok
data
354 Enter mail, end with "." on a line by itself
huhy huhy huhy huhy huhy
.
250 2.0.0 2AMEXpVF008699 Message accepted for delivery
quit
221 2.0.0 huhy closing connection
Connection closed by foreign host.
root@slave1:~#

客户端进行查看验证

进入交互式后;
回车
user 用户名 (选择用户)
pass 用户密码
quit (退出)

root@slave1:~# telnet www.hoyeong.com 110
Trying 192.168.200.160...
Connected to www.hoyeong.com.
Escape character is '^]'.
+OK [XCLIENT] Dovecot (Ubuntu) ready.
user mail2
+OK
pass 000000
+OK Logged in.
list
+OK 1 messages:
1 367
.
retr 1
+OK 367 octets
Return-Path: <[email protected]>
Received: from www.hoyeong.com ([192.168.200.101])
        by huhy (8.15.2/8.15.2/Debian-22ubuntu3) with SMTP id 2AMEXpVF008699
        for [email protected]; Tue, 22 Nov 2022 14:35:02 GMT
Date: Tue, 22 Nov 2022 14:33:51 GMT
From: mail <[email protected]>
Message-Id: <202211221435.2AMEXpVF008699@huhy>

huhy huhy huhy huhy huhy
.
quit
+OK Logging out.
Connection closed by foreign host.
root@slave1:~#

Ubuntu一键部署

#!bin/bash

ip=192.168.200.160

domain=hoyeong.com

mailuser1=mail1

userpd1=000000

mailuser2=mail2

userpd2=000000


apt install -y sendmail

#博主空了完善
echo "####交互式配置sendmail####"
sendmailconfig
y
#输入n回车,表示不使用默认配置的sendmail,而是自定义
n
#直接回车
ENTER回车
#输入邮件域名,2级即可
hoyeong.com
一直回车到底然后会生效配置文件(然后需要等待一会时间)
#然后直接回车即可,默认会重启sendmail
Reload the running sendmail now with the new configuration?


echo "#####修改配置文件#####"
cat > /etc/hostname <<eof
$domain
eof

sed -i 's/Addr=127.0.0.1/Addr=0.0.0.0/'g /etc/mail/sendmail.mc

cat > /etc/mail/local-host-names <<eof
$domain
$ip
eof

cp /etc/mail/access{,.bak}

cat > /etc/mail/access eof
Connect:$doamin	            RELAY
Connect:$ip		            RELAY
eof

cd /etc/mail
make

systemctl restart sendmail

echo "#####创建用户#####"
useradd -m $mailuser1
useradd -m $mailuser2
passwd $mailuser1 <<eof
$userpd1
$userpd1
eof
passwd $mailuser2 <<eof
$userpd2
$userpd2
eof
echo "#####服务端配置完毕#####"


标签:www,mail,sendmail,hoyeong,huhy,192.168,Ubuntu,服务器,com
From: https://www.cnblogs.com/hwiung/p/16917901.html

相关文章

  • Ubuntu20.04.1安装JDK17
    1.下载https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz2.解压缩到指定目录创建目录sudomkdir/usr/lib/java解压缩到该目录sudot......
  • Mac如何连接远程服务器
    Mac如何连接远程服务器iTerm2可以以明文保存密码,实现快速连接远程服务器,但是,密码最好不要暴露在明文里。我们可以借助更为通用的方法。在Mac这样的类UINX系统中,使用iTer......
  • 服务器 局域网(内网)电脑IP地址修改
    服务器网络突然连不上,有线网无线网均不行参考https://zhuanlan.zhihu.com/p/373735540能连上网之后要重新恢复成之前的内网IP,修改IPV4设置配置IP(原来的内网IP),掩码(255.......
  • ssh与服务器安全实战
    ssh原理ssh是一种协议标准,其目的是实现安全远程登录以及其它安全网络服务。SSH仅仅是一协议标准,其具体的实现有很多,既有开源实现的OpenSSH,也有商业实现方案。使用范围最......
  • go 1.12以下,给服务器增加包依赖的自动化脚本
    前言旧版的go不支持module,所以包依赖需要手动引入。本文仅记录用过的脚本,方便以后复制。需要对具体的包增加具体的脚本#本脚本,需要在服务上预先配置好go1.9,GOPATH,GOROO......
  • 利用Docker、云服务器、mongodb搭建自己的测试平台
    准备一个云服务器购买一个云服务器,在阿里云,腾讯云上购买即可。然后创建一个实例,安装Linux操作系统,我安装的是CentOS。记住账号和密码,可以使用ssh远程登录即可。 ......
  • ubuntu gdb不能attch
    在进入gdb后,直接使用attachID,出现下面的情况:Couldnotattachtoprocess.Ifyouruidmatchestheuidofthetargetprocess,checkthesettingof/proc/sys/ke......
  • 恒创科技:高速云服务器怎么选?需要注意这几点
    ​云服务器是我们使用较多的一款网站服务器,不仅拥有许多优点,而且对于用户来说也是性价比较高的选择。但是很多人对于云服务器的选择还存在一些问题,那么下面我们就来讲讲......
  • Jenkins服务器的部署与简单使用(第三周)
    Jenkins安装安装依赖:https://www.jenkins.io/zh/doc/book/installing/    #CPU、内存、磁盘安装Java8、在2.361.1及以上版本开始要求Java11:aptinstallopenj......
  • 134-腾讯云服务器装Tengine
    第1步:yuminstallgccgcc-c++autoconfautomake出现类似如下错误:Couldnotresolvehost:mirrors.tencentyun.com;Unknownerror百度结果说:我们需要把DNS恢复为......