php - 在 Laravel 中使用 Office365 直接发送 SMTP
问题描述
我正在尝试为 Office365 设置直接发送 SMTP 方法,但收到一条错误消息:
Swift_TransportException:无法与主机 {our-tenant-id}.mail.protection.outlook.com 建立连接 [无法建立连接,因为目标机器主动拒绝了它。
Microsoft 文档说这些是必需的设置:
| Server/smart host | Your MX endpoint, for example, contoso-com.mail.protection.outlook.com
| Port | Port 25
| TLS/StartTLS | Enabled
| Email address | Any email address for one of your Office 365 accepted domains.
| | This email address does not need to have a mailbox.
所以这些是我在.env
文件中使用的设置:
MAIL_DRIVER=smtp
MAIL_HOST={our-tenant-id}.mail.protection.outlook.com
MAIL_PORT=25
MAIL_USERNAME=mailbox@ourdomain.co.uk
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
根据文档,我还检查了我们的 SPF 记录,我可以确认它包含正确的条目。
以前有没有其他人设置过这个或者知道我可能哪里出错了?
解决方案
我们使用类似的设置。请注意,建立与办公室的连接可能会有点慢,因此您需要对电子邮件进行排队,以确保用户无需等待。
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=mailbox@ourdomain.co.uk
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
推荐阅读
- ruby-on-rails - 无法将我的 csv 文件加载到我的 rails 数据库
- html - 没有固定内容位置的css导航栏位置
- javascript - 如何使用 AJAX 通过网页向 ESP8266 发送值?
- google-chrome - 在 chrome 扩展中获取 YouTube 频道 ID
- php - 修改数组中的对象正在更改会话值
- python-3.x - tkinter - 滚动条不显示小部件
- dart - 获取目录中的文件名和目录名
- javascript - 通过兄弟的文本获取特定兄弟元素之后的元素
- javascript - Reed API 获取请求和基本身份验证的网络错误
- c++ - 将返回相同类对象的方法添加到 C++ 中的现有类