第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

SwiftMailer 像 PHPMailer 一樣強(qiáng)制 SMTPAuth

SwiftMailer 像 PHPMailer 一樣強(qiáng)制 SMTPAuth

PHP
寶慕林4294392 2022-01-02 17:25:33
我正在努力使用 Exchange 在線帳戶從網(wǎng)絡(luò)發(fā)送郵件。最近,在遷移到 Laravel 時(shí),我發(fā)現(xiàn)與 PHPMailer 配合良好的現(xiàn)有設(shè)置不適用于基于 SwiftMailer 的 Laravel。PHPMailer 的工作原理:$data = new PHPMailer(true);$data->CharSet = 'UTF-8';$data->isSMTP();$data->Host = config('mail.host');$data->SMTPAuth = true;          // apparently this line does the trick$data->Username = config('mail.username');$data->Password = config('mail.password');$data->SMTPSecure = config('mail.encryption');$data->Port = config('mail.port');$data->setFrom('site@mydomain.com','site mailer');$data->addAddress('me@mydomain.com', 'Me');$data->Subject = 'Wonderful Subject PHPMailer';$data->Body = 'Here is the message itself PHPMailer';$data->send();與 SwiftMailer 相同的邏輯:$transport = (new Swift_SmtpTransport(config('mail.host'), config("mail.port"), config('mail.encryption')))    ->setUsername(config('mail.username'))    ->setPassword(config('mail.password'));$mailer = new Swift_Mailer($transport);$message = (new Swift_Message('Wonderful Subject'))  ->setFrom(['site@mydomain.com'=>'site mailer'])  ->setTo(['me@mydomain.com'=>'Me'])  ->setBody('Here is the message itself');$numSent = $mailer->send($message);SwiftMailer,給出錯(cuò)誤:530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxxxxxxxxxx.xxxxxxxx.prod.outlook.com]兩種情況下的 SMTP 服務(wù)器smtp-mail.outlook.com和端口 587 相同NB是的,我很清楚其他地方使用的建議mydomain-com.mail.protection.outlook.com和端口 25。但是這樣做后,垃圾郵件中會(huì)收到消息,原因是“我們無法驗(yàn)證發(fā)件人的身份”,這是我無法接受的行為。我們談?wù)摰氖巧倭?,所以?duì)其他/第 3 方群發(fā)郵件服務(wù)不感興趣。到目前為止,我的發(fā)現(xiàn)是,這$phpMailer->SMTPAuth = true;改變了游戲規(guī)則。如果沒有這一行,它會(huì)產(chǎn)生與 SwiftMailer 相同的錯(cuò)誤。 問題是如何強(qiáng)制執(zhí)行相同的行為SwiftMailer?如前所述,我實(shí)際上使用了 Laravel 郵件,但為了這個(gè)示例的目的,我直接提取了 SwiftMailer 調(diào)用。編輯: SwiftMailer 有$transport->setAuthMode(),它應(yīng)該與$phpMailer->AuthType. 為兩者嘗試了可用的 CRAM-MD5、LOGIN、PLAIN、XOAUTH2 值。PHPMailer 與所有這些一起工作,除了 XOAUTH2。對(duì)于 SwiftMailer,這些都沒有改變?nèi)魏螙|西,仍然給出錯(cuò)誤。EDIT2:我確實(shí)有 SPF 記錄(DNS TXT)v=spf1 include:spf.protection.outlook.com -all已解決:添加tls到 Swift 運(yùn)輸結(jié)構(gòu)中。顯然PHPMailer的默認(rèn)設(shè)置為TLS,因?yàn)閏onfig('mail.encryption')是null。
查看完整描述

1 回答

?
一只萌萌小番薯

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊

處理用 Java 發(fā)送郵件,但這里的基本問題似乎是一樣的:

如果您通過端口 587 連接,您最初會(huì)啟動(dòng)一個(gè)普通連接,您必須通過顯式發(fā)送 STARTTLS 命令來啟動(dòng) TLS。您必須告訴 JavaMail 這樣做,否則它會(huì)嘗試在不安全的情況下進(jìn)行。除非建立 TLS 連接,否則 SMTP 服務(wù)器不會(huì)發(fā)送任何身份驗(yàn)證機(jī)制信息,因此 JavaMail 假設(shè)不需要身份驗(yàn)證并嘗試在沒有身份驗(yàn)證的情況下發(fā)送郵件。

因此,您似乎需要在此處明確指定您希望它也成為加密連接。

Swift_SmtpTransport 構(gòu)造函數(shù)的第三個(gè)參數(shù)執(zhí)行此操作,提供“ssl”或“tls”:

new Swift_SmtpTransport('smtp.example.org', 587, 'ssl'); // or
new Swift_SmtpTransport('smtp.example.org', 587, 'tls');

使用 phpMailer 版本,您需要 $data->SMTPSecure 來處理那部分。


查看完整回答
反對(duì) 回復(fù) 2022-01-02
  • 1 回答
  • 0 關(guān)注
  • 204 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)