2012-09-28 56 views
1

發送電子郵件這是我的代碼使用Gmail和VB.NET發送電子郵件:無法從VB.net

 Try 
      Dim SmtpServer As New SmtpClient() 
      SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "mypassword") 
      SmtpServer.Port = 587 
      SmtpServer.Host = "smtp.gmail.com" 
      SmtpServer.EnableSsl = True 

      mail = New MailMessage() 
      mail.From = New MailAddress("[email protected]", "Asked for help", System.Text.Encoding.UTF8) 
      Mail.To.Add("[email protected]") 
      Mail.Subject = "A help query has been raised" 
      mail.Body = frm_dashboard.user_data_fetch.Item(1, 0).Value.ToString + " " + ask_for_help.txt_message_ask_help.Text 
      SmtpServer.Send(Mail) 
      MessageBox.Show("Mail sent") 
     Catch ex As Exception 
      MsgBox(ex.ToString()) 
      MessageBox.Show("Oops something went wrong.") 
     End Try 

但是,這表明我這個錯誤: -

enter image description here

+1

在設置證書之前,試試'SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network:SmtpServer.UseDefaultCredentials = false'?改編自Gmail和.Net上的[標準答案](http://stackoverflow.com/a/32336/15639)(在C#中,但直接轉換爲VB) – MarkJ

回答

1

這是我有它的順序,你可能想試試這個:

Dim SMTP As New SmtpClient("smtp.gmail.com") 
SMTP.Credentials = New System.Net.NetworkCredential("gmailID", "password") 
SMTP.EnableSsl = True 
SMTP.Port = "587" 
SMTP.Send(Mail) 

另外請注意,我實際上並沒有使用「 @ gmail.com「時傳遞我的憑據。