2017-10-16 3 views
0

이메일을 보내기 위해이 파일을 사용했지만 제출할 때 "Line 41 : smtp.Send (msg);"가 표시되었습니다. 오류. 나는 이것이 무엇이 잘못된 것인지 모른다. 도와 주셔서 감사합니다!SmtpClient.Send (msg); 오류

Stack Trace: 
 

 

 
[SmtpException: 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] 
 
    System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +1844406 
 
    System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) +46 
 
    System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) +88 
 
    System.Net.Mail.SmtpClient.Send(MailMessage message) +1856 
 
    XinNing_Web.Contact.btnSubmit_Click(Object sender, EventArgs e) in E:\Projects\ASP.NET\XinNing_Web\XinNing_Web\Contact.aspx.cs:41 
 
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9767618 
 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204 
 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 
 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 
 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 
 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1738

+0

이중 인증 설정을 확인하십시오. 일반적으로이 문제는 dev 컴퓨터와 다른 IP 주소의 Gmail 공급자를 사용할 때 발생합니다. 현재 컴퓨터에서 Gmail에 로그인하고 여기에 제공된대로 계정 인증을 확인하십시오. https://support.google.com/accounts/answer/1144110?hl=ko –

+0

정말 고마워요. 알 겠어! –

답변

0

당신이 메일을 보내려고 시도하는에서 Gmail 계정에서 true로 덜 안전한 응용 프로그램을 허용

public partial class Contact : Page 
 
    { 
 
     protected void btnSubmit_Click(object sender, EventArgs e) 
 
     { 
 
      MailMessage msg = new MailMessage(); 
 
      msg.From = new MailAddress("[email protected]"); 
 
      msg.To.Add("[email protected]"); 
 
      msg.Subject = txtSubject.Text; 
 
      msg.Body = txtFirstName.Text + " " + txtLastName.Text + "'s phone number is: " + txtPhone.Text + ". <br />" + "Email Address is: " + txtEmail.Text + "Message: <br />" + txtMessage.Text; 
 
      msg.IsBodyHtml = true; 
 

 
      SmtpClient smtp = new SmtpClient(); 
 
      smtp.Host = "smtp.gmail.com"; 
 
      
 
      System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); 
 
      NetworkCred.UserName = "[email protected]"; 
 
      NetworkCred.Password = "xxxxx"; 
 
      smtp.UseDefaultCredentials = true; 
 
      smtp.Credentials = NetworkCred; 
 
      smtp.Port = 587; 
 
      smtp.EnableSsl = true; 
 
      smtp.Send(msg); 
 
      lblMessage.Text = "Email has been successfully sent!"; 
 

 
     } 
 
    }

.

내 계정으로 이동 -> 로그인 & 보안 -> 덜 안전한 앱 허용 (페이지 하단).

이 오류로 인해 시간이 약간 걸렸습니다.