我正在尝试在我的 VB.Net Windows 应用程序(VS 2010)中发送电子邮件,但我得到了
未找到 SMTP 主机
我的代码如下,
Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New Net.NetworkCredential("mymailid@gmail.com", "mypassword")
SmtpServer.Port = 25
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New MailMessage()
Dim addr() As String = TextBox1.Text.Split(",")
Try
mail.From = New MailAddress("mymailid@gmail.com", "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
SmtpServer.SendAsync(mail, mail.Subject)