2012-11-16 4 views
2

Visual Studio 2012를 사용하여 간단한 양식을 만들었지 만 내 Gmail 계정으로 이메일을 보내지는 않지만 페이지가 제대로 실행되지만 보내기 버튼을 누르면 오류가 발생합니다.문의 양식이 내 Gmail 계정에 이메일을 보내지 않습니다

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. j8sm1567623paz.30

Description: An unhanded 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 Must issue a STARTTLS command first. j8sm1567623paz.30

Source Error: 
Line 14: 
Line 15:   
Line 16:   mailClient.Send(message) 
Line 17:   
Line 18:  

Source File: C:\Website SVN II\test\contact.aspx.vb Line: 16 

출처 :

Imports System.Net.Mail 

Partial Class contact 
Inherits System.Web.UI.Page 

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    sendMail(txtEmail.Text, txtMessage.Text) 
End Sub 

Protected Sub sendMail(ByVal From As String, ByVal body As String) 
    Dim mailservername As String = "smtp.gmail.com" 
    Dim message As MailMessage = New MailMessage(From, "[email protected]", "feedback", body) 
    Dim mailClient As SmtpClient = New SmtpClient 

    mailClient.Host = mailservername 
    mailClient.Send(message) 
    message.Dispose() 
End Sub 

End Class 

HTML.

 first name 
     <asp:TextBox ID="txtFName" runat="server"></asp:TextBox> 

     <br /> 
     <br /> 

     last name 
     <asp:TextBox ID="txtLName" runat="server"></asp:TextBox> 

     <br /> 
     <br /> 

     email 
     <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> 

     <br /> 
     <br />    

     message: 
     <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine"></asp:TextBox> 

     <br /> 

     <asp:Button ID="Button1" runat="server" Text="Send" /> 
+1

보인다. – itsbruce

+0

관련 (Gmail/.net 정보), http://stackoverflow.com/questions/3615674/vb-net-sending-email-using-gmail-account, http://stackoverflow.com/questions/10690015/sending- email-using-gmail-give-a-time-out-error, http://stackoverflow.com/questions/1905019/vb-net-program-that-sends-email – Kratz

답변

1

두 가지 :

  1. 당신은 HTTPS를 사용해야합니다.
  2. 귀하의 계정에 대한 자격 증명을 제공해야합니다.

여기 here에서 C# 예제입니다 :

using System.Net; 
using System.Net.Mail; 

var fromAddress = new MailAddress("[email protected]", "From Name"); 
var toAddress = new MailAddress("[email protected]", "To Name"); 
const string fromPassword = "fromPassword"; 
const string subject = "Subject"; 
const string body = "Body"; 

var smtp = new SmtpClient 
      { 
       Host = "smtp.gmail.com", 
       Port = 587, 
       EnableSsl = true, 
       DeliveryMethod = SmtpDeliveryMethod.Network, 
       UseDefaultCredentials = false, 
       Credentials = new NetworkCredential(fromAddress.Address, fromPassword) 
      }; 
using (var message = new MailMessage(fromAddress, toAddress) 
        { 
         Subject = subject, 
         Body = body 
        }) 
{ 
    smtp.Send(message); 
} 

vb.net 버전 : 메일 서버가 보안 연결을 원하고 당신이 하나를 요구하지 않는 것처럼

Private Sub Button1_Click(ByVal sender As System.Object, _ 
    ByVal e As System.EventArgs) Handles Button1.Click 
    Dim SmtpServer As New SmtpClient() 
    SmtpServer.Credentials = New Net.NetworkCredential 
       ("[email protected]", "password") 
    SmtpServer.Port = 587 
    SmtpServer.Host = "smtp.gmail.com" 
    SmtpServer.EnableSsl = True 

    mail = New MailMessage() 
    Dim addr() As String = TextBox1.Text.Split(",") 
    Try 
     mail.From = New MailAddress("[email protected]", 
      "Web Developers", System.Text.Encoding.UTF8) 

     Dim i As Byte 
     For i = 0 To addr.Length - 1 
      mail.To.Add(addr(i)) 
     Next 
     mail.Subject = TextBox3.Text 
     mail.Body = TextBox4.Text 
     If ListBox1.Items.Count <> 0 Then 
      For i = 0 To ListBox1.Items.Count - 1 
       mail.Attachments.Add(New Attachment 
        (ListBox1.Items.Item(i))) 
      Next 
     End If 
     mail.DeliveryNotificationOptions = 
       DeliveryNotificationOptions.OnFailure 
     mail.ReplyTo = New MailAddress(TextBox1.Text) 
     SmtpServer.Send(mail) 
    Catch ex As Exception 
     MsgBox(ex.ToString()) 
    End Try 
End Sub 
관련 문제