您的位置:首页 > 运维架构 > Linux

linux下基于smtp协议的C++客户端debug经验

2015-10-14 22:00 609 查看
我所使用的是Ubuntu下saslauthd+ postfix + dovecot搭建的环境。

1.解决mail.log出现的warning: SASL authentication failure: cannot connect to saslauthd

原因:postfix没有找到saslauthd的工作目录,由于postfix的工作目录默认在/var/spool/postfix/var/run/saslauthd中;而saslauthd默认的工作目录为/var/run/saslauthd中,从而导致postfix无法连接saslauthd服务。

解决办法:
打开 saslauthd的配置文件
sudo vim /etc/default/saslauthd

OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

如果没有这个路径,使用mkdir命令创建就行了。
然后再创建一个符号链接:
sudo ln -s /var/spool/postfix/var/run/saslauthd/ /var/run/saslauthd

测试:
重启:
sudo /etc/init.d/saslauthd restart

添加用户
sudo adduser postfix sasl

testsaslauthd -u username -p password(username 替换为你的用户名, password:替换为你的密码)

输出0: OK "Success."则代表成功

2.解决: postfix/smtp[19420] :disconnect from localhost[127.0.0.1]

打开你的postfix的配置文件:
sudo vim /etc/postfix/main.cf
然后修改或者添加下面的内容:

#你所用的smtp服务器,记得要在在服务器中开启smtp

myhostname = smtp.qq.com

#你用的smtp服务的域名
mydomain = qq.com

然后重启postfix服务:
sudo /etc/init.d/postfix restart
就可以了。

3.解决:在输入auth login之后出现error:535 authentication failed

第一种:

可能就是你的右键客户端没有开启smtp服务。
我用来测试的是smtp.163.com。只要登陆网易邮箱,然后设置一下就行了。
详细请看:http://help.163.com/09/1223/14/5R7P6CJ600753VB8.html?servCode=6010376

第二种:

可能就是你输入的不是你的smtp的独立密码,以163的邮箱为例,在你设置的时候它会要求你设置一个独立的密码。

第三种:

可能是最麻烦的一种可能:你没有安装postfix,或者安装了postfix,没有开启sasl和pop3服务。
首先:你要安装这两个软件:
我的是Ubuntu版本:
apt-get install sasl2-bin postfix dovecot-pop3d
在安装了postfix之后,需要配置postfix
下列命令和直接修改/etc/postfix/main.cf是一样的。
sudo
postconf -e 'smtpd_sasl_type = dovecot'

sudo postconf -e 'smtpd_sasl_path = private/auth-client'

sudo postconf -e 'smtpd_sasl_local_domain ='

sudo postconf -e 'smtpd_sasl_security_options = noanonymous'

sudo postconf -e 'broken_sasl_auth_clients = yes'

sudo postconf -e 'smtpd_sasl_auth_enable = yes'

sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'

sudo postconf -e 'inet_interfaces = all'

sudo
postconf -e 'home_mailbox = Maildir/'

然后在main.cf 中的mydestination中添加下列几个地址: example.com, mail.example.com, localhost.example.com, localhost

这是因为默认情况postfix只接收发到@mail.example.com的邮件,而不接收@example.com的邮件。

修改
saslauthd 配置文件:

sudo vim /etc/default/saslauthd
将START设为yes
START = yes
重启sasl:
sudo /etc/init.d/saslauthd
restart

然后修改etc/dovecot/dovecot.conf,在最后添加下面内容:
mail_location
= maildir:~/Maildir

#postfix中设置了mailbox类型为maildir,这是对应的设置。

disable_plaintext_auth
= no

#默认情况下,dovecot是不允许plaintext类型的认证

输入命令:
sudo
dovecot reload

重新加载配置,让你的配置生效

最后重启postfix:

sudo /etc/init.d/postfix restart

测试:

telnet localhost 25

ehlo lcal

auth login

4.解决:操作正常,smtp返回正常,但是收不到邮件

smtp一般都会对邮件的中文字数有限制来防止垃圾邮件,因此要有一定字数的中文才能发送。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: