linux环境下启用postfix服务进行域名邮件收发
安装服务
[root@kittod ~]# dnf install postfix mailx -y
1.编辑postfix服务的主配置文件
[root@kittod ~]# vim /etc/postfix/main.cf
87 # INTERNET HOST AND DOMAIN NAMES
88 #
89 # The myhostname parameter specifies the internet hostname of this
90 # mail system. The default is to use the fully-qualified domain name
91 # from gethostname(). $myhostname is used as a default value for many
92 # other configuration parameters.
93 #
94 myhostname = mail.baidu.com
95 #myhostname = virtual.domain.tld
96
97 # The mydomain parameter specifies the local internet domain name.
98 # The default is to use $myhostname minus the first component.
99 # $mydomain is used as a default value for many other configuration
100 # parameters.
101 #
102 mydomain = baidu.com
104 # SENDING MAIL
105 #
106 # The myorigin parameter specifies the domain that locally-posted
107 # mail appears to come from. The default is to append $myhostname,
108 # which is fine for small sites. If you run a domain with multiple
109 # machines, you should (1) change this to $mydomain and (2) set up
110 # a domain-wide alias database that aliases each user to
111 # user@that.users.mailhost.
112 #
113 # For the sake of consistency between sender and recipient addresses,
114 # myorigin also specifies the default domain name that is appended
115 # to recipient addresses that have no @domain part.
116 #
117 #myorigin = $myhostname
118 myorigin = $mydomain
120 # RECEIVING MAIL
121
122 # The inet_interfaces parameter specifies the network interface
123 # addresses that this mail system receives mail on. By default,
124 # the software claims all active interfaces on the machine. The
125 # parameter also controls delivery of mail to user@[ip.address].
126 #
127 # See also the proxy_interfaces parameter, for network addresses that
128 # are forwarded to us via a proxy or network address translator.
129 #
130 # Note: you need to stop/start Postfix when this parameter changes.
131 #
132 inet_interfaces = all
152 # The mydestination parameter specifies the list of domains that this
153 # machine considers itself the final destination for.
154 #
155 # These domains are routed to the delivery agent specified with the
156 # local_transport parameter setting. By default, that is the UNIX
157 # compatible delivery agent that lookups all recipients in /etc/passwd
158 # and /etc/aliases or their equivalent.
183 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
272 # Alternatively, you can specify the mynetworks list by hand, in
273 # which case Postfix ignores the mynetworks_style setting.
274 #
275 # Specify an explicit list of network/netmask patterns, where the
276 # mask specifies the number of bits in the network part of a host
277 # address.
278 #
279 # You can also specify the absolute pathname of a pattern file instead
280 # of listing the patterns here. Specify type:table for table-based lookups
281 # (the value on the table right-hand side is not used).
282 #
283 mynetworks = 192.168.226.0/24, 127.0.0.0/8
315 relay_domains = $mydestination
2.重新启动服务
[root@kittod ~]# systemctl restart postfix
3.发邮件给redhat用户
[root@kittod ~]# mail redhat@haha.com
Subject: test02
这是测试内容
EOT
4.切换到redhat用户进行查看
[root@kittod ~]# su - redhat
Last login: Mon Oct 25 15:46:13 CST 2021 on pts/0
[redhat@kittod ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/redhat": 2 messages 1 unread
1 root Mon Oct 25 15:46 21/597 "test01"
>U 2 root Mon Oct 25 17:53 20/615 "test02"
& 2
Message 2:
From root@haha.com Mon Oct 25 17:53:03 2021
Return-Path: <root@haha.com>
X-Original-To: redhat@haha.com
Delivered-To: redhat@haha.com
Date: Mon, 25 Oct 2021 17:53:03 +0800
To: redhat@haha.com
Subject: test02
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=utf-8
From: root <root@haha.com>
X-UID: 6
Status: RO
这是测试内容
&