• 如何在Modoboa邮件服务器中托管多个域

    本教程将向您展示如何使用Modoboa设置多个电子邮件域(虚拟托管),这是一个易于使用且开源的邮件托管解决方案。为了学习本教程,假设您已经使用一个域名设置了Modoboa邮件服务器。 你需要做什么 如果要承载多个邮件域,则需要 在Modoboa管理面板中添加新的邮件域和用户。 为新邮件域创建MX、A、SPF、DKIM和DMARC记录。 为多个域设置Webmail、Postfix和Dovecot PTR记录用于检查发送方的IP地址是否与HELO主机名匹配。添加新邮件域时,无需添加其他PTR记录。 步骤1:在Modoboa管理面板中添加其他域 使用管理员帐户登录Modoboa管理面板。(https://mail.your-domain.com/admin)然后转到“域”选项卡,单击“添加”按钮添加新域。 然后在“名称”字段中输入主域名。强烈建议您启用DKIM签名,这有助于提高您的域声誉。在键选择器字段中,您可以输入一个随机单词,如modoboa。选择2048作为密钥长度。 在下一个屏幕中,您可以选择为您的域创建管理员帐户。SMTP协议要求邮件服务器应该有一个[email protected]地址。 点击提交按钮,你的新域名将被添加到Modoboa中。 要添加电子邮件地址,请转到“域”选项卡,然后单击第二个域名。 然后单击邮箱。 单击添加按钮并选择帐户。 然后选择简单用户作为角色。在用户名字段中输入电子邮件地址,然后输入密码。 在下一个屏幕中,您可以选择为此电子邮件地址创建别名。 单击提交按钮后,将创建电子邮件地址。 步骤2:为新邮件域创建MX、A、SPF、DKIM和DMARC记录 MX和一张唱片 在DNS管理器中,为新域添加MX记录,如下所示。 Record Type    Name      Value MX   @ mail.domain2.com A记录指向邮件服务器的IP地址。 Record Type Name Value A mail IP-address-of-mail-server 如果您的服务器使用IPv6地址,请确保添加AAAA记录。 SPF、DKIM和DMARC记录 然后创建SPF记录,以允许MX主机为新邮件域发送电子邮件。 Record Type Name Value TXT   @   v=spf1 mx ~all 要创建DKIM记录,我们需要获取公钥。转到Modoboa管理面板,在域选项卡中选择第二个域名。在DNS部分,单击显示密钥按钮。 将显示第二个域的公钥。有两种格式。我们只需要绑定/命名格式。 转到DNS管理器,创建一个TXT记录,输入modoboa_名称字段中的domainkey。(回想一下,在管理面板中添加第二个域名时,我们使用了modoboa作为选择器。)复制括号中的所有内容并粘贴到值字段中。删除所有双引号。DNS管理器可能会要求您删除其他无效字符,例如回车符。 请注意,您的DKIM记录可能需要一些时间才能传播到Internet。根据您使用的域注册器,您的DNS记录可能会立即传播,或者传播可能需要24小时。你可以去https://www.dmarcanalyzer.com/dkim/dkim-check/,输入modoboa作为选择器,并输入您的域名以检查DKIM记录传播。 要创建DMARC记录,请转到DNS管理器并添加TXT记录。在名称字段中,输入_dmarc。在“值”字段中,输入以下内容: v=DMARC1; p=none; pct=100; rua=mailto:[email protected] 上述DMARC记录是一个安全的起点。要查看DMARC的完整解释,请查看以下文章。 创建DMARC记录以保护您的域名免受电子邮件欺骗 第3步:为多个域设置Webmail、Postfix和Dovecot 让第一个域的用户使用邮件是有道理的。域1。com和第二个域的用户使用邮件。域2。com访问网络邮件时。 首先,我们需要将第二个邮件域添加到允许的主机列表中。编辑设置。py文件。 sudo nano /srv/modoboa/instance/instance/settings.py 找到下面几行。 ALLOWED_HOSTS = [ 'mail.domain1.com', ] 添加第二个域。 ALLOWED_HOSTS = [ 'mail.domain1.com', 'mail.domain2.com', ] 保存并关闭文件。然后重新启动uWSGI以使更改生效。 sudo systemctl restart uwsgi 接下来,我们需要在第二个域中创建一个Nginx虚拟主机文件。将工作目录更改为/etc/nginx/sites enabled。 cd /etc/nginx/sites-enabled 将第一个邮件域虚拟主机文件的内容复制到第二个域虚拟主机文件。 sudo cp mail.domain1.com.conf mail.domain2.com.conf 编辑第二个域虚拟主机文件。 sudo nano mail.domain2.com.conf 找到下面这行。 server_name mail.domain1.com; 我们需要将服务器名称更改为mail。域2。通用域名格式 server_name mail.domain2.com; 服务器名称有两个实例,您需要同时更改这两个实例。(请注意,您不应更改SSL证书路径中的域名。)然后注释掉下面三行,因为这个上游已经在邮件中定义了。域1。通用域名格式。conf文件。 upstream modoboa { server unix:/run/uwsgi/app/modoboa_instance/socket fail_timeout=0; } 保存并关闭文件。然后测试Nginx配置。 sudo nginx -t 如果测试成功,请重新加载Nginx以使更改生效。 sudo systemctl reload nginx 确保在Debian/Ubuntu服务器上安装了cerbot。 sudo apt install certbot python3-certbot-nginx 在CentOS/RHEL上,运行以下命令安装certbot。 sudo dnf install certbot python3-certbot-nginx 现在,使用Certbot nginx插件为所有邮件域获取TLS证书,这样您将拥有一个包含多个域名的TLS证书,邮件客户端将不会抛出安全警告。 sudo certbot certonly --nginx --agree-tos -d mail.domain1.com,mail.domain2.com --cert-name mail.domain1.com --email your-email-address 请注意,在上面的命令中,我们使用第一个邮件域指定了证书名,该域将在文件路径中使用,因此您不必在Postfix或Dovecot配置文件中更改文件路径。还要注意,我们告诉certbot只获取证书,而不安装证书(certonly)。 当它询问您是否要更新现有证书以包含新域时,请回答U并按Enter键。 现在您应该会看到以下消息,这表明已成功获取多域证书。 重新加载Nginx以获取新证书。 sudo systemctl reload nginx 您现在应该能够使用不同的域来访问webmail。此外,您还需要重新加载Postfix SMTP服务器和Dovecot IMAP服务器,以便让它们获取新证书。 sudo systemctl reload postfix dovecot 在计算机或移动设备上使用邮件客户端 启动你的桌面电子邮件客户端,比如Mozilla Thunderbird,并添加第二个域的邮件帐户。 在“传入服务器”部分,选择IMAP协议,输入mail。域2。com作为服务器名,选择端口143和STARTTLS。选择普通密码作为身份验证方法。 在“发送”部分,选择SMTP协议,输入mail。域2。com作为服务器名,选择端口587和STARTTLS。选择普通密码作为身份验证方法。 提示:您还可以将端口993用于IMAP的SSL/TLS加密,将端口465用于SMTP的SSL/TLS加密。您不应该在邮件客户端中使用端口25作为SMTP端口来提交发送的电子邮件。 虽然Postfix SMTP服务器和Dovecot IMAP服务器在与其他服务器通信时使用第一个邮件域(mail.domain1.com)的主机名,但它们现在使用的是多域证书,因此邮件客户端不会显示证书警告。 SPF和DKIM检查 现在,您可以使用桌面电子邮件客户端或webmail客户端向[email protected]发送测试电子邮件,并获得免费的电子邮件身份验证报告。这是我从25号端口收到的报告。通用域名格式 别忘了在网上测试你的电子邮件分数https://www.mail-tester.com还可以使用GlockApps测试电子邮件的放置。 如果DKIM检查失败,您可以转到https://www.dmarcanalyzer.com/dkim/dkim-check/查看您的DKIM记录是否有任何错误。 如果你的电子邮件仍被标记为垃圾邮件呢? 在这篇文章中,我有更多的建议:7个有效的建议来阻止你的电子邮件被标记为垃圾邮件。虽然这需要一些时间和精力,但在应用这些技巧后,你的电子邮件最终会被放入收件箱。 多个邮件域的RDN? 反向DNS(RDN),又名PTR记录,用于检查发送方的IP地址是否与HELO主机名匹配。添加新邮件域时,无需添加其他PTR记录。您的RDN应该只设置一个主机名,即Postfix中设置的主机名,可以通过以下命令显示。 postconf myhostname rDNS是IP地址的记录。这不是域名的记录。如果只有一个IP地址,那么只需要一条指向一个主机名的rDNS记录。反向DNS检查不会验证发件人:域在您的电子邮件中,只要您的IP地址有rDNS记录,并且主机名可以解析回相同的IP地址,您就可以通过反向DNS检查。 此外,在一台服务器上托管多个域时,不需要在Postfix中更改以下设置。 我的主机名 肌动蛋白 我的目的地 托管电子邮件服务,如G Suite和Microsoft Exchange Online,都使用一个主机名作为服务器,为客户发送电子邮件。G套件用户发送的电子邮件都使用谷歌。主机名中的com和Microsoft Exchange Online用户发送的电子邮件都使用outlook。主机名中的com。对于其他电子邮件服务提供商,如Mailchimp、SendinBlue、SendPluse等,情况也是如此。它们都为单个服务器使用一个主机名,而一个IP地址只有一个RDN记录。 如何在Modoboa邮件服务器中托管多个域 Autodiscover and AutoConfig make it easy to configure a desktop or mobile mail client. The end user just need to enter a name, email address and password to set up his/her mail account, without having to enter the SMTP or IMAP server details. Setting up Autodiscover and AutoConfig for multiple domains requires 2 simple steps. First, create CNAME records for the second domain in your DNS manager, autoconfig.domain2.com CNAME mail.domain2.com autodiscover.domain2.com CNAME mail.domain2.com Then go to the Nginx virtual host directory. cd /etc/nginx/sites-enabled/ Copy the autoconfig virtual host for the second domain. sudo cp autoconfig.domain1.com.conf autoconfig.domain2.com.conf Edit the new virtual host file. sudo nano autoconfig.domain2.com.conf Find the following line. server_name autoconfig.domain1.com; We need to change the server_name to autoconfig.domain2.com server_name autoconfig.domain2.com; Then comment out the following 3 lines, because this upstream has already been defined in the autoconfig.domain1.com.conf file, we can’t define it again. upstream automx { server unix:/run/uwsgi/app/automx_instance/socket fail_timeout=0; } Save and close the file. Then test Nginx configuartion. sudo nginx -t If the test is successful, reload Nginx for the changes to take effect. sudo systemctl reload nginx Now you can test the Autodiscover and AutoConfig feature in Microsoft Outlook and Mozilla Thunderbird mail client. By default, AutoMX will send the first hostname (mail.domain1.com) to mail clients who request Autodiscover and AutoConfig info, which means Microsoft Outlook and Mozilla Thunderbird would use mail.domain1.com as the SMTP server and IMAP server for the second domain. This works, but isn’t perfect. If you want Microsoft Outlook and Mozilla Thunderbird to use mail.domain2.com as SMTP and IMAP server address for the second domain, then edit the AutoMX configuration file. sudo nano /etc/automx.conf Create a new section for the second domain at the end of this file. [domain2.com] Then copy the lines from the [global] section and change the domain name. [domain2.com] backend = sql action = settings account_type = email host = postgres://modoboa:[email protected]/modoboa query = SELECT first_name || ' ' || last_name AS display_name, email, SPLIT_PART(email, '@', 2) AS domain FROM core_user WHERE email='%s' AND is_active result_attrs = display_name, email smtp = yes smtp_server = mail.domain2.com smtp_port = 587 smtp_encryption = starttls smtp_auth = plaintext smtp_auth_identity = ${email} smtp_refresh_ttl = 6 smtp_default = yes imap = yes imap_server = mail.domain2.com imap_port = 143 imap_encryption = starttls imap_auth = plaintext imap_auth_identity = ${email} imap_refresh_ttl = 6 pop = yes pop_server = mail.domain2.com pop_port = 110 pop_encryption = starttls pop_auth = plaintext pop_auth_identity = ${email} Save and close the file. Then restart AutoMX. sudo systemctl restart uwsgi Wrapping Up That’s it! I hope this tutorial helped you host multiple email domains with Modoboa. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care ?

    2022.03.23 浏览:287