iT邦幫忙

0

撰寫Gmail發信功能問題_C#

leo226 2017-04-02 22:49:2740854 瀏覽

各位先進好,最近想寫一個利用Gmail或Yahoo的mail server發信的程式,不過遇到了瓶頸,不知各位先進是否有相關經驗,或目前正在使用此功能的先進可以幫忙一下,感激不盡!
以下是我的簡單設定內容:
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential("account", "password");
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Send(mms);
整個程式mail server的部份我有改用公司的mail server設定,是確定可以發送出去的沒問題,只是改用gmail或yahoo的mail server就會遇到問題,目前已遇到兩三種error,找了google大師都沒有找到解答,故上來求救一下!

Error log 1:(使用gmail)
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

下列方法已做,將gmail的[允許安全性較低的應用程式] 設定處於啟用狀態=>啓用
solution 1 for case 2: go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps.

Error log 2:(使用yahoo)
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

已經不知道還有什麼方法可以嚐試解決了,先謝謝各位幫忙了~感激!


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
石頭
iT邦高手 1 級 ‧ 2017-04-03 07:38:44

您好!
這裡是文章區
如需提問請轉發問區XD

  1. 建立應用程式密碼登入 登入密碼改成google產生的16位密碼
    參考連結:https://support.google.com/accounts/answer/185833
  2. 將smtp.UseDefaultCredentials = false; 改成true或註解掉

應該就可以寄送mail了

我要留言

立即登入留言