2014-03-04 2 views
0

나는 프로그램을 전송하는 간단한 전자 메일을 만들려고 노력하고 있지만,이 두 smtpclients메일 링 시도 개체 참조?

Dim client As SmtpClient 
Dim SmtpServer As New SmtpClient() 

당신이 SmtpServer을 인스턴스화 있지만 client을 선언하고 object reference not set to an instance of an object

Try 
     Dim mail As MailMessage 
     Dim client As SmtpClient 
     Dim SmtpServer As New SmtpClient() 
     Dim fromAddress As String 
     Dim toAddress1 As String 
     Dim toAddress2 As String 
     Dim toAddress3 As String 
     Dim subject As String 
     Dim message As String 
     SmtpServer.Credentials = New Net.NetworkCredential("*********@gmail.com", "**********") 
     client.UseDefaultCredentials = False 

     fromAddress = FromEmail.Text 
     If ToEmail1.Visible = True Then 
      toAddress1 = ToEmail1.Text 
     ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True Then 
      toAddress1 = ToEmail1.Text 
      toAddress2 = ToEmail2.Text 
     ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True And ToEmail3.Visible = True Then 
      toAddress1 = ToEmail1.Text 
      toAddress2 = ToEmail2.Text 
      toAddress3 = ToEmail3.Text 
     End If 

     subject = "Subject" 
     Message = "Message" 

     mail = New MailMessage(fromAddress, toAddress1, subject, Message) 
     client = New SmtpClient("Smtp.live.com") 

     client.Port = 587 
     Dim SMTPUserInfo As New System.Net.NetworkCredential("[email protected]", "password") 
     client.Credentials = SMTPUserInfo 

     client.Send(mail) 
     MsgBox("sent") 
Catch ex As Exception 
      MsgBox(ex.Message.ToString()) 
End Try 
+0

어디에서 오류가 발생 했습니까? 오류 메시지의 전체 텍스트는 무엇입니까? 이 WebForms 또는 MVC입니까? 어떤 버전의 .NET? –

+0

스택 오버플로에 오신 것을 환영합니다! 'NullReferenceException'의 거의 모든 경우는 같습니다. 일부 힌트는 "[.NET의 NullReferenceException은 무엇입니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)"를 참조하십시오. –

답변

0

을 말했을 때 그것은 나를 혼동하고있다 . 그럼 당신이 할

client.UseDefaultCredentials = False 

나는 예외가 제기되는 곳이라고 생각합니다. 코드는 SmtpServer를 통해 일부 메일을 Google 계정에서 보내고 다른 줄은 클라이언트를 통해 핫메일 계정에서 보내는 것처럼 보입니다. 게다가 SmtpServer는 config.sys에 정의 된 일부 서버를 사용하고 있습니다.