AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 641261
Accepted
MultiformeIngegno
MultiformeIngegno
Asked: 2014-11-01 15:21:25 +0800 CST2014-11-01 15:21:25 +0800 CST 2014-11-01 15:21:25 +0800 CST

设置 Postfix+Dovecot 从数据库读取

  • 772

我正在尝试设置Postfix和Dovecot,后者将虚拟用户存储在 MySQL 数据库中,遵循本指南(但在这里我回顾一下所有内容,因为我在评论后修复的指南中有一些“错误”)。序言:我从 Ubuntu 存储库安装了、Postfix和Dovecot。postfix-mysqldovecot-mysql

让我们从 Postfix 配置开始:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no   
readme_directory = no

myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

relay_domains = *
virtual_alias_maps = proxy:mysql:/etc/postfix/virtual_alias_maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/virtual_mailbox_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/virtual_mailbox_maps.cf
virtual_mailbox_base = /home/vmail
virtual_mailbox_limit = 512000000
virtual_minimum_uid = 5000
virtual_transport = virtual
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
local_transport = virtual
local_recipient_maps = $virtual_mailbox_maps
transport_maps = hash:/etc/postfix/transport

smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/run/dovecot/auth-client
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = $smtpd_sasl_security_options
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/private/server.crt
smtpd_tls_key_file = /etc/ssl/private/server.key
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_tls_loglevel = 1

然后我创建了用户vmail来存储电子邮件:

groupadd -g 5000 vmail
useradd -u 5000 -g vmail -s /usr/bin/nologin -d /home/vmail -m vmail

以及 MySQL 数据库和用户来存储有关域和虚拟用户的信息:

CREATE DATABASE postfix_db;
USE postfix_db;
CREATE USER postfix_user@localhost IDENTIFIED BY 'password';
GRANT ALL ON postfix_db.* TO postfix_user@localhost;
FLUSH PRIVILEGES;

然后我创建了与域、转发和用户相关的表:

CREATE TABLE `domains` (
  `domain` varchar(50) NOT NULL default "",
  PRIMARY KEY  (`domain`),
  UNIQUE KEY `domain` (`domain`)
);


CREATE TABLE `forwardings` (
  `source` varchar(80) NOT NULL default "",
  `destination` text NOT NULL,
  PRIMARY KEY  (`source`)
);

CREATE TABLE `users` (
  `email` varchar(80) NOT NULL default "",
  `password` varchar(20) NOT NULL default "",
  `quota` varchar(20) NOT NULL default '20971520',
  `domain` varchar(255) NOT NULL default "",
  UNIQUE KEY `email` (`email`)
);

我在表中添加了我的域(正确设置了 A 和 MX 记录):

INSERT INTO `domains` VALUES ('virtualdomain.tld');

以及与该域相关的帐户:

INSERT INTO `users` VALUES ('[email protected]', ENCRYPT('password'), '20971520', 'virtualdomain.tld');

然后我创建了一个自签名证书:

cd /etc/ssl/private/
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key
chmod 400 server.key
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
chmod 444 server.crt

然后是我在 Postfix 配置中引用的文件:

/etc/postfix/virtual_alias_maps.cf

user = postfix_user
password = hunter2
hosts = localhost
dbname = postfix_db
table = domains
select_field = domain
where_field = domain

/etc/postfix/virtual_mailbox_domains.cf

user = postfix_user
password = hunter2
hosts = localhost
dbname = postfix_db
table = forwardings
select_field = destination
where_field = source

/etc/postfix/virtual_mailbox_maps.cf

user = postfix_user
password = hunter2
hosts = localhost
dbname = postfix_db
table = users
select_field = concat(domain,'/',email,'/')
where_field = email

接着

touch /etc/postfix/transport
postmap /etc/postfix/transport

现在我删除了默认的 Dovecot 配置文件,将其替换为:

protocols = imap
auth_mechanisms = plain
passdb {
    driver = sql
    args = /etc/dovecot/dovecot-sql.conf
}
userdb {
    driver = sql
    args = /etc/dovecot/dovecot-sql.conf
}

service auth {
    unix_listener auth-client {
        group = postfix
        mode = 0660
        user = postfix
    }
    user = root
}

mail_home = /home/vmail/%d/%u
mail_location = maildir:~

ssl_cert = </etc/ssl/private/server.crt
ssl_key = </etc/ssl/private/server.key

我创建了/etc/dovecot/dovecot-sql.conf文件:

driver = mysql
connect = host=localhost dbname=postfix_db user=postfix_user password=hunter2
# The new name for MD5 is MD5-CRYPT so you might need to change this depending on version
default_pass_scheme = MD5-CRYPT
# Get the mailbox
user_query = SELECT '/home/vmail/%d/%u' as home, 'maildir:/home/vmail/%d/%u' as mail, 5000 AS uid, 5000 AS gid, concat('dirsize:storage=',  quota) AS quota FROM users WHERE email = '%u'
# Get the password
password_query = SELECT email as user, password, '/home/vmail/%d/%u' as userdb_home, 'maildir:/home/vmail/%d/%u' as userdb_mail, 5000 as  userdb_uid, 5000 as userdb_gid FROM users WHERE email = '%u'
# If using client certificates for authentication, comment the above and uncomment the following
#password_query = SELECT null AS password, ‘%u’ AS user

...最后重新启动 dovecot 和后缀:

service postfix dovecot restart

问题是,当我尝试向 发送电子邮件时[email protected],我在日志中看到:

NOQUEUE: reject: RCPT from blablabla.com[xxx.xxx.xxx.xxx]: 451 4.3.0 <[email protected]>: Temporary lookup failure; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<blablabla.com>

并且邮件因错误而退回

550 5.1.1 "Recipient address rejected: User unknown in virtual alias table"
ubuntu
  • 2 2 个回答
  • 1039 Views

2 个回答

  • Voted
  1. Best Answer
    masegaloeh
    2014-11-01T17:12:36+08:002014-11-01T17:12:36+08:00

    看起来,你的virtual_alias_maps和virtual_mailbox_domains被交换了。尝试重命名它们

    mv /etc/postfix/virtual_alias_maps.cf /tmp/virtual_mailbox_domains.tmp
    mv /etc/postfix/virtual_mailbox_domains.cf /etc/postfix/virtual_alias_maps.cf 
    mv /tmp/virtual_mailbox_domains.tmp /etc/postfix/virtual_mailbox_domains.cf
    

    别忘了跑postfix reload。

    • 3
  2. devatnull
    2014-11-01T19:28:17+08:002014-11-01T19:28:17+08:00

    我确定 Dovecot 是创建 auth 文件的那个,因为 postfix 与 dovecot 对话,dovecot 进行身份验证,因此在您的“dovecot.conf”中添加:

    path = /var/run/dovecot/auth-client
    

    像这样进入客户端块:

    service auth {
        unix_listener auth-client {
            path = /var/run/dovecot/auth-client
            group = postfix
            mode = 0660
            user = postfix
        }
    

    或者

    service auth {
        unix_listener /var/run/dovecot/auth-client {
            group = postfix
            mode = 0660
            user = postfix
        }
    

    重启鸽舍

    检查是否创建了 /var/run/dovecot/auth-client

    输入ls -l /var/run/dovecot/auth-client以确认。

    然后重试。

    • 2

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve