在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证 [英] check SMTP authentication without sending email and without using pear in PHP

查看:37
本文介绍了在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不发送邮件和不使用PHP中使用PEAR的情况下检查SMTP身份验证。他们有什么方法可以检查主机、端口、用户名和密码的身份验证吗?

我查看了SWIFTMAILLER,它显示正在发送电子邮件进行身份验证。 http://swiftmailer.org/docs/sending.html#smtp-with-a-username-and-password

phpmaeller上也是如此。 https://github.com/PHPMailer/PHPMailer/blob/master/examples/smtp.phps

推荐答案

诚然,这不是最干净的解决方案,但它会奏效。下面复制了一个expect脚本,该脚本将连接到SMTP服务器,尝试进行身份验证,然后退出会话并断开连接。如果expect脚本的最后一行输出是235 2.7.0 Authentication successful(或响应代码以2xx开头的另一个类似响应),则使用提供的凭据验证成功,否则验证失败。您可以使用shell_exec()从您的PHP脚本调用此expect脚本,并分析输出以测试是否可以在给定一组凭据的情况下使用SMTP服务器进行身份验证。

                #!/usr/bin/expect
                set mailserver "smtp.smtpserver.com";         #fqdn of SMTP server
                set credentials "AG1xxxxxxxxxxxxxxxxxxxDNy";  #this string should be "usernamepassword" base64-encoded.

                spawn telnet $mailserver 25
                expect "failed" {
                                send_user "$mailserver: connect failed
"
                                exit
                        } "2?? *" {
                        } "4?? *"   {
                                exit
                        } "refused" {
                                send_user "$mailserver: connect refused
"
                                exit
                        } "closed" {
                                send_user "$mailserver: connect closed
"
                                exit
                        } timeout {
                                send_user "$mailserver: connect to port 25 timeout
"
                                exit
                        }
                send "HELO foo.com
"
                expect "2?? *" {
                } "5?? *" {
                        exit
                } "4?? *" {
                        exit
                }

                send "AUTH PLAIN $credentials
";
                expect "2?? *" {
                } "5?? *" {
                        exit
                } "4?? *" {
                        exit
                }

                send "QUIT
"
                exit

这篇关于在不发送电子邮件和在PHP中不使用PEAR的情况下检查SMTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆