Postifx、Dovecot

邮件协议

简单邮件传输协议(Simple Mail Transfer Protocol,SMTP):用于发送和中转发出的电子邮件,占用服务器的25/TCP端口

邮局协议版本3(Post Office Protocol 3):用于将电子邮件存储到本地主机,占用服务器的110/TCP端口

Internet消息访问协议版本4(Internet Message Access Protocol 4):用于在本地主机上访问邮件,占用服务器的143/TCP端口

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
vim /etc/hostname mail.linuxprobe.com hostname mail.linuxprobe.com iptables -F service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] cat /etc/named.conf 1 // 2 // named.conf 3 // 4 // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS 5 // server as a caching only nameserver (as a localhost DNS resolver only). 6 // 7 // See /usr/share/doc/bind*/sample/ for example named configuration files. 8 // 9 10 options { 11 listen-on port 53 { any; }; 12 listen-on-v6 port 53 { ::1; }; 13 directory "/var/named"; 14 dump-file "/var/named/data/cache_dump.db"; 15 statistics-file "/var/named/data/named_stats.txt"; 16 memstatistics-file "/var/named/data/named_mem_stats.txt"; 17 allow-query { any; }; 18 ………………省略部分输出信息……………… cat /etc/named.rfc1912.zones zone "linuxprobe.com" IN { type master; file "linuxprobe.com.zone"; allow-update {none;}; }; cat /var/named/linuxprobe.com.zone systemctl restart named systemctl enable named ln -s '/usr/lib/systemd/system/named.service' '/etc/systemd/system/multi-user.target.wants/named.service' yum install postfix Loaded plugins: langpacks, product-id, subscription-manager rhel7 | 4.1 kB 00:00 (1/2): rhel7/group_gz | 134 kB 00:00 (2/2): rhel7/primary_db | 3.4 MB 00:00 Package 2:postfix-2.10.1-6.el7.x86_64 already installed and latest version Nothing to do systemctl disable iptables

Postfix参数

参数作用
myhostname邮局系统的主机名
mydomain邮局系统的域名
myorigin从本机发出邮件的域名名称
inet_interfaces监听的网卡接口
mydestination可接收邮件的主机名或域名
mynetworks设置可转发哪些主机的邮件
relay_domains设置可转发哪些网域的邮件

  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
vim /etc/postfix/main.cf ………………省略部分输出信息……………… 68 # INTERNET HOST AND DOMAIN NAMES 69 # 70 # The myhostname parameter specifies the internet hostname of this 71 # mail system. The default is to use the fully-qualified domain name 72 # from gethostname(). $myhostname is used as a default value for many 73 # other configuration parameters. 74 # 75 #myhostname = host.domain.tld 76 myhostname = mail.linuxprobe.com ………………省略部分输出信息……………… 78 # The mydomain parameter specifies the local internet domain name. 79 # The default is to use $myhostname minus the first component. 80 # $mydomain is used as a default value for many other configuration 81 # parameters. 82 # 83 mydomain = linuxprobe.com 85 # SENDING MAIL 86 # 87 # The myorigin parameter specifies the domain that locally-posted 88 # mail appears to come from. The default is to append $myhostname, 89 # which is fine for small sites. If you run a domain with multiple 90 # machines, you should (1) change this to $mydomain and (2) set up 91 # a domain-wide alias database that aliases each user to 92 # user@that.users.mailhost. 93 # 94 # For the sake of consistency between sender and recipient addresses, 95 # myorigin also specifies the default domain name that is appended 96 # to recipient addresses that have no @domain part. 97 # 98 #myorigin = $myhostname 99 myorigin = $mydomain 103 # The inet_interfaces parameter specifies the network interface 104 # addresses that this mail system receives mail on. By default, 105 # the software claims all active interfaces on the machine. The 106 # parameter also controls delivery of mail to user@[ip.address]. 107 # 108 # See also the proxy_interfaces parameter, for network addresses that 109 # are forwarded to us via a proxy or network address translator. 110 # 111 # Note: you need to stop/start Postfix when this parameter changes. 112 # 113 #inet_interfaces = all 114 #inet_interfaces = $myhostname 115 #inet_interfaces = $myhostname, localhost 116 inet_interfaces = all 133 # The mydestination parameter specifies the list of domains that this 134 # machine considers itself the final destination for. 135 # 136 # These domains are routed to the delivery agent specified with the 137 # local_transport parameter setting. By default, that is the UNIX 138 # compatible delivery agent that lookups all recipients in /etc/passwd 139 # and /etc/aliases or their equivalent. 140 # 141 # The default is $myhostname + localhost.$mydomain. On a mail domain 142 # gateway, you should also include $mydomain. 143 # 144 # Do not specify the names of virtual domains - those domains are 145 # specified elsewhere (see VIRTUAL_README). 146 # 147 # Do not specify the names of domains that this machine is backup MX 148 # host for. Specify those names via the relay_domains settings for 149 # the SMTP server, or use permit_mx_backup if you are lazy (see 150 # STANDARD_CONFIGURATION_README). 151 # 152 # The local machine is always the final destination for mail addressed 153 # to user@[the.net.work.address] of an interface that the mail system 154 # receives mail on (see the inet_interfaces parameter). 155 # 156 # Specify a list of host or domain names, /file/name or type:table 157 # patterns, separated by commas and/or whitespace. A /file/name 158 # pattern is replaced by its contents; a type:table is matched when 159 # a name matches a lookup key (the right-hand side is ignored). 160 # Continue long lines by starting the next line with whitespace. 161 # 162 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". 163 # 164 mydestination = $myhostname , $mydomain 165 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 166 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, useradd boss echo "linuxprobe" | passwd --stdin boss Changing password for user boss. passwd: all authentication tokens updated successfully. systemctl restart postfix systemctl enable postfix ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service' yum install dovecot Loaded plugins: langpacks, product-id, subscription-manager ………………省略部分输出信息……………… Installing: dovecot x86_64 1:2.2.10-4.el7 rhel 3.2 M Installing for dependencies: clucene-core x86_64 2.3.3.4-11.el7 rhel 528 k Transaction Summary =============================================================================== Install 1 Package (+1 Dependent package) Total download size: 3.7 M Installed size: 12 M Is this ok [y/d/N]: y Downloading packages: ------------------------------------------------------------------------------- Total 44 MB/s | 3.7 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : clucene-core-2.3.3.4-11.el7.x86_64 1/2 Installing : 1:dovecot-2.2.10-4.el7.x86_64 2/2 Verifying : 1:dovecot-2.2.10-4.el7.x86_64 1/2 Verifying : clucene-core-2.3.3.4-11.el7.x86_64 2/2 Installed: dovecot.x86_64 1:2.2.10-4.el7 Dependency Installed: clucene-core.x86_64 0:2.3.3.4-11.el7 Complete! vim /etc/dovecot/dovecot.conf ………………省略部分输出信息……………… 23 # Protocols we want to be serving. 24 protocols = imap pop3 lmtp 25 disable_plaintext_auth = no ………………省略部分输出信息……………… 44 # Space separated list of trusted network ranges. Connections from these 45 # IPs are allowed to override their IP addresses and ports (for logging and 46 # for authentication checks). disable_plaintext_auth is also ignored for 47 # these networks. Typically you'd specify your IMAP proxy servers here. 48 login_trusted_networks = 192.168.10.0/24 vim /etc/dovecot/conf.d/10-mail.conf 1 ## 2 ## Mailbox locations and namespaces 3 ## 4 # Location for users' mailboxes. The default is empty, which means that Dovecot 5 # tries to find the mailboxes automatically. This won't work if the user 6 # doesn't yet have any mail, so you should explicitly tell Dovecot the full 7 # location. 8 # 9 # If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u) 10 # isn't enough. You'll also need to tell Dovecot where the other mailboxes are 11 # kept. This is called the "root mail directory", and it must be the first 12 # path given in the mail_location setting. 13 # 14 # There are a few special variables you can use, eg.: 15 # 16 # %u - username 17 # %n - user part in user@domain, same as %u if there's no domain 18 # %d - domain part in user@domain, empty if there's no domain 19 # %h - home directory 20 # 21 # See doc/wiki/Variables.txt for full list. Some examples: 22 # 23 # mail_location = maildir:~/Maildir 24 mail_location = mbox:~/mail:INBOX=/var/mail/%u 25 # mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n ………………省略部分输出信息……………… # su - boss Last login: Sat Aug 15 16:15:58 CST 2017 on pts/1 mkdir -p mail/.imap/INBOX exit systemctl restart dovecot systemctl enable dovecot ln -s '/usr/lib/systemd/system/dovecot.service' '/etc/systemd/system/multi-user.target.wants/dovecot.service' mail Heirloom Mail version 12.5 7/5/10.Type ? for help. "/var/mail/root": 3 messages 3 unread > U 1 user@localhost.com Fri Jul 10 09:58 1631/123113 "[abrt] full crash r" U 2 Anacron Sat Aug 15 13:33 18/624 "Anacron job 'cron.dai" U 3 boss Sat Aug 15 19:02 118/3604 "Hello~" &> 3 Message 3: From boss@linuxprobe.com Sat Aug 15 19:02:06 2017 Return-Path: X-Original-To: root@linuxprobe.com Delivered-To: root@linuxprobe.com From: "boss" To: Subject: Hello~ Date: Sat, 15 Aug 2017 19:02:06 +0800 Content-Type: text/plain; charset="gb2312" ………………省略部分输出信息……………… 当您收到这封邮件时,证明我的邮局系统实验已经成功! > quit Held 3 messages in /var/mail/root su - bin This account is currently not available. mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/mail/root": 4 messages 4 new > U 1 user@localhost.com Fri Jul 10 09:58 1630/123103 "[abrt] full crash r" U 2 Anacron Wed Aug 19 17:47 17/619 "Anacron job 'cron.dai" U 3 boss Sat Aug 15 19:02 118/3604 "Hello~" U 4 boss Wed Aug 19 18:49 116/3231 "你好,用户Bin。" &> 4 Message 4: From boss@linuxprobe.com Wed Aug 19 18:49:05 2017 Return-Path: <boss@linuxprobe.com> X-Original-To: bin@linuxprobe.com Delivered-To: bin@linuxprobe.com From: "boss" <boss@linuxprobe.com> To: <bin@linuxprobe.com> Subject: 你好,用户Bin。 Date: Wed, 19 Aug 2017 18:49:05 +0800 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0006_01D0DAAF. B9104E90" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdDabKrQzUHVBTgRQMaCtUs VtqfL1Q== Content-Language: zh-cn Status: R Content-Type: text/plain; charset="gb2312" ………………省略部分输出信息……………… 这是一封发给用户Bin的文件。 &> quit Held 4 messages in /var/mail/root cat /etc/aliases # # Aliases in this file will NOT be expanded in the header from # Mail, but WILL be visible over networks or from /bin/mail. # # >>>>>>>>>> The program "newaliases" must be run after # >> NOTE >> this file is updated for any changes to # >>>>>>>>>> show through to sendmail. # # Basic system aliases -- these MUST be present. mailer-daemon: postmaster postmaster: root # General redirections for pseudo accounts. bin: root daemon: root adm: root lp: root sync: root shutdown: root halt: root mail: root www: webmaster webmaster: root noc: root security: root hostmaster: root info: postmaster marketing: postmaster sales: postmaster support: postmaster # trap decode to catch security attacks decode: root # Person who should get root's mail #root: marc cat /etc/aliases # # Aliases in this file will NOT be expanded in the header from # Mail, but WILL be visible over networks or from /bin/mail. # # >>>>>>>>>> The program "newaliases" must be run after # >> NOTE >> this file is updated for any changes to # >>>>>>>>>> show through to sendmail. # # Basic system aliases -- these MUST be present. mailer-daemon: postmaster postmaster: root # General redirections for pseudo accounts. xxoo: root bin: root daemon: root adm: root lp: root ………………省略部分输出信息……………… mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/mail/root": 5 messages 1 new 4 unread U 1 user@localhost.com Fri Jul 10 09:58 1631/123113 "[abrt] full crash report" U 2 Anacron Wed Aug 19 17:47 18/629 "Anacron job 'cron.daily' on mail.linuxprobe.com" U 3 boss Wed Aug 19 18:44 114/2975 "hello" 4 boss Wed Aug 19 18:49 117/3242 "你好,用户Bin。" >N 5 boss Wed Aug 19 19:18 115/3254 "这是一封发送给xxoo用户的邮件。"

浙ICP备11005866号-12