2013-10-01 39 views
18

下面的代碼在本地工作正常,但如果上傳它上godaddy它不工作。SMTP服務器需要安全連接或客戶端未通過身份驗證。如果上傳上godaddy

錯誤:顯示

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

Line 53:   
Line 54:   smtp.EnableSsl = true; 
Line 55:   smtp.Send(message); 
Line 56: 
Line 57: 

PLZ檢查下面的代碼

MailMessage message = new MailMessage(); 
    message.From = new MailAddress(emailid.Text); 

    message.To.Add(new MailAddress("[email protected]")); 

    message.Subject = "NaatKhawan's Feedback"; 

    message.Body = "Selected: " + DropDownList1.Text.ToString() + "<br/><br/>Name: " + name.Text.ToString() + " <br/><br/>Email: " + emailid.Text.ToString() + " <br/><br/>Contact Number: " + phone.Text.ToString() + " <br/><br/>Message:<br/> " + remabox.Text.ToString(); 

    message.IsBodyHtml = true; 

    // finaly send the email: 
    SmtpClient smtp = new SmtpClient(); 
    smtp.Host = "smtp.gmail.com"; 

    smtp.Port = 587; 
    smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "123"); 

    smtp.EnableSsl = true; 
    smtp.Send(message); 
    lbltxt.Visible = true; 
    name.Text = ""; 
    emailid.Text = ""; 
    phone.Text = ""; 
    remabox.Text = ""; 

    lbltxt.Text = "Thank you for supporting NaatKhawan"; 

回答

34

您應該啓用應用程序來訪問Gmail帳戶。 This link will help you

+4

這是什麼樣的鏈接?它有什麼作用?我是否需要在所有要使用我的帳戶的計算機上運行它? – Robert

+1

看看http://stackoverflow.com/questions/34851484/how-to-send-an-email-in-net-according-to-new-google-security-policies – 2016-01-20 08:28:25

16

我有同樣的問題。

我發現這個解決方案:

谷歌可能會在一些應用或設備不使用最新安全標準的企圖阻止跡象。由於這些應用和設備更容易侵入,因此阻止這些應用和設備有助於保持帳戶安全。

不支持最新的安全標準的應用程序的一些例子包括:

在您的iPhone或iPad上的郵件應用程序與iOS 6以下 的郵件應用程式Windows手機的8.1版本 一些桌面前上像Microsoft Outlook和Mozilla Thunderbird這樣的郵件客戶端 因此,您必須在您的谷歌帳戶中啓用不太安全的登錄。

標誌到谷歌帳戶後,請訪問:

https://www.google.com/settings/security/lesssecureapps

+0

哇,謝謝你。沒有其他答案爲我解決了這個問題。我覺得這是Google最近的變化,現在應該將此答案更新並接受爲「答案」。 – AlexVPerl

+0

謝謝艾丁....救了我很多時間。 –

0

我也有這個問題從我的本地應用程序發送電子郵件,並嘗試了許多不同的意見。

經過幾個小時的鬥爭後,事實證明,這個問題與我有2個谷歌帳戶,我使用我的第二個帳戶,所有設置都是正確的事實有關,我甚至在這個帳戶上啓用lesssecureapps,但它仍然沒有工作。我嘗試的最後一件事是改變SmtpClient設置,以使用我的其他Gmail帳戶,這一切都神奇地工作。

1

我剛剛遇到同樣的問題。

試圖Aidin伊斯拉米的答案,它只是做了部分工作:

在這裏啓用不夠安全的應用訪問後: https://www.google.com/settings/security/lesssecureapps 我設法從我的本地機器發送電子郵件,但不能從我的虛擬主機。

然後我發現這個谷歌支持頁面: https://support.google.com/accounts/answer/6009563

Still having trouble signing in?

If you’ve tried all the options above but are still unable to sign in to your account on the app, try the following:

Go to https://accounts.google.com/DisplayUnlockCaptcha on your device's browser. Enter your username and password, then type the letters on the screen. Go back to the app and try signing in again.

按下按鈕,在DisplayUnlockCaptcha一切正常後!

希望這可以幫助其他人。祝你好運。

相關問題