无法使用 Snipe IT 中的 Office 365 SMTP 设置发送邮件 PHP
Unable to send mail using Office 365 SMTP settings in Snipe IT PHP
在 PHP
中使用 swift 邮件程序发送电子邮件时遇到以下问题
[2020-06-22 00:38:48] production.ERROR: Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to tcp://smtp.office365.com:587 (Permission denied) {"userId":1,"email":"xxx@dhdigital.co.in","exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to tcp://smtp.office365.com:587 (Permission denied) at /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269)
[stacktrace]
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, 'stream_socket_c...', '/var/www/snipei...', 272, Array)
#1 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(272): stream_socket_client('tcp://smtp.offi...', 13, 'Permission deni...', 30, 4, Resource id #662)
#2 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#4 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#5 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(451): Swift_Mailer->send(Object(Swift_Message), Array)
#6 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(235): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#7 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(64): Illuminate\Mail\Mailer->send(Object(Illuminate\Support\HtmlString), Array, Object(Closure))
...(redacted)
邮件设置正确我交叉验证了它们。系统托管在 CentOS 上,firewalld 被禁用。
更新
SMTP 设置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=dhprojects@dhdigital.co.in
MAIL_PASSWORD=xxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDR=dhprojects@dhdigital.co.in
MAIL_FROM_NAME=dhprojects@dhdigital.co.in
MAIL_REPLYTO_ADDR=dhprojects@dhdigital.co.in
MAIL_REPLYTO_NAME=SnipeIT
MAIL_BACKUP_NOTIFICATION_ADDRESS=xxx@dhdigital.co.in
我终于意识到问题出在我的 CentOS 上的 selinux 设置上。 SELinux 是强制执行的,所以它不允许我在那个特定端口上建立连接。一旦我禁用它,事情就开始工作了。
在 PHP
中使用 swift 邮件程序发送电子邮件时遇到以下问题[2020-06-22 00:38:48] production.ERROR: Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to tcp://smtp.office365.com:587 (Permission denied) {"userId":1,"email":"xxx@dhdigital.co.in","exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to tcp://smtp.office365.com:587 (Permission denied) at /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269)
[stacktrace]
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, 'stream_socket_c...', '/var/www/snipei...', 272, Array)
#1 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(272): stream_socket_client('tcp://smtp.offi...', 13, 'Permission deni...', 30, 4, Resource id #662)
#2 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#4 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#5 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(451): Swift_Mailer->send(Object(Swift_Message), Array)
#6 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(235): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#7 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(64): Illuminate\Mail\Mailer->send(Object(Illuminate\Support\HtmlString), Array, Object(Closure))
...(redacted)
邮件设置正确我交叉验证了它们。系统托管在 CentOS 上,firewalld 被禁用。
更新 SMTP 设置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=dhprojects@dhdigital.co.in
MAIL_PASSWORD=xxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDR=dhprojects@dhdigital.co.in
MAIL_FROM_NAME=dhprojects@dhdigital.co.in
MAIL_REPLYTO_ADDR=dhprojects@dhdigital.co.in
MAIL_REPLYTO_NAME=SnipeIT
MAIL_BACKUP_NOTIFICATION_ADDRESS=xxx@dhdigital.co.in
我终于意识到问题出在我的 CentOS 上的 selinux 设置上。 SELinux 是强制执行的,所以它不允许我在那个特定端口上建立连接。一旦我禁用它,事情就开始工作了。