[C#] 寄送 Gmail 出現 The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. 解決方法

2021-01-12

最近要用 Gmail 寄信,我語言是用 C# ,但是我相信大家遇到問題都一樣,我遇到這問題 The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. 我 google 了個遍,找到許多答案,但是可能是時間太久遠的關係我測試都失敗,重點是以前的我都寫爛了怎麼可能會不成功,但是當我要放棄之時,我仔細看了..Google 的說明,最後測試成功,接下來我就是分享一下步驟..


錯誤訊息:
Server Error in '/' Application.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at...


在 2022-05 之後 Google 又改規則了,可以參考 https://blog.no2don.com/2022/06/c-gmail-2022.html


1.你要有 Google 帳號。

2. 到這網址把 低安全性打開 https://myaccount.google.com/lesssecureapps



3. 然後寫到程式佈署到你的機器上,因為可能不是你家的 IP 或是在其他國家等等,之後試著寄信讓他錯,錯了之後 到這網址看看

https://myaccount.google.com/notifications ,他應該會列出有人試著要用你的帳號登入寄信服務,你要允許他




4. 登入你的 Gmail 記得 把 IMAP 打開



5. 試著,再重試第三條寄送看看,如果不行 就到這網址 https://www.google.com/accounts/DisplayUnlockCaptcha 這一步最關鍵,這是這一次我無法測試失敗的主要原因。


上述五點完成應該就可以寄送了,真的浪費我幾個小時找原因,希望可以幫助到你。

接下來附上,我最近測試過可以用的 code .



當麻許的超技八 2014 | Donma Hsu Design.