System.Net.Mail VB.NET 3.5 System.Net.Mail.SmtpException

时间:2013-04-06 18:56:26

标签: vb.net smtp

我已经彻底搜索了网络以找到解决方案并且尚未找到解决方案。 我正在尝试建立一个简单的邮件客户端,通过SMTP将文本文档作为原始文本发送。为此,我使用VB.Net版本3.5

下的System.Net.Mail库

每当我尝试发送消息时,都会收到System.Net.Mail.SmtpException。 我尝试使用不同的邮件提供商,在不同的设置下,还没有解决这个问题。这个问题已经在3台不同的计算机上进行了测试 代码如下:

Private Sub SendEmailMessage()
Try
If My.Computer.Network.IsAvailable Then
        If DataValid() Then
                'Data is valid, send the eMail.
                Dim MailReceiver As String = txtReceiver.Text
                'Create the eMail Message.
                'Dim message As New MailMessage(from:=txtMailAddress.Text, to:=MailReceiver, subject:="(MTG) <CARD> " & ID, body:="<p>" & ConstructedFileString() & "<p>")
                Dim message As New MailMessage
                Dim MessageFrom As New MailAddress(txtMailAddress.Text)
                Dim MessageTo As New MailAddress(MailReceiver)
                With message
                     .From = MessageFrom
                     .To.Add(MailReceiver)
                     .Subject = "(MTG) CARD " & ID
                     .IsBodyHtml = True
                     .Body = "<p>" & ConstructedFileString() & "<p>"
                 End With
                 'Establish eMail Client
                 Dim emailClient As New SmtpClient()
                 Dim emailCredentials As New Net.NetworkCredential

                With emailCredentials
                    .UserName = txtMailAddress.Text
                    .Password = txtPassword.Text
                    .Domain = "gmail.com"
                End With

                With emailClient
                    .Host = txtHostServer.Text
                    .Port = txtPort.Text
                    .Credentials = emailCredentials
                    .EnableSsl = chkSSL.Checked
                    .Timeout = 5000
                End With

                'Dim MailDomain As String = ""
                'Dim PositionAt As Byte = 0
                'PositionAt = txtMailAddress.Text.IndexOf("@")
                'For i = PositionAt + 1 To Len(txtMailAddress.Text)
                '    MailDomain = MailDomain & txtMailAddress.Text.Chars(i)
                'Next
                'Debug.Print(MailDomain)

                If My.Computer.Network.Ping(hostNameOrAddress:=emailClient.Host) Then
                    'Send the message.
                    emailClient.Send(message)
                Else
                    'Could not ping, do not send.
                    ErrorOut("Could not reach the eMail Server.")
                End If


           Else
                'Data is not valid, do not send the eMail.
           End If
    Else
        ErrorOut("No network could be found. Check your network configurations.")
    End If
Catch ex As Security.SecurityException
    'Security exception
    ErrorOut("A Security Exception was raised.")
Catch ex As Net.NetworkInformation.NetworkInformationException
    'Network info exception
    ErrorOut("Exception raised when retrieving network information.")
Catch ex As Net.NetworkInformation.PingException
    'Ping exception
    ErrorOut("Exception raised when pinging the network.")
Catch ex As Net.Mail.SmtpFailedRecipientException
    'Recipient exception
    ErrorOut("Mail Recipient Exception raised.")
Catch ex As Net.Mail.SmtpException
    'Mail Server Exception
    ErrorOut("Mail Server Exception raised")
Catch ex As Exception
    'Generic Exception raised.
    ErrorOut("General Exception raised", True)
End Try
End Sub 

非常感谢任何有关此事的帮助,谢谢。

堆栈追踪:

System.Net.Mail.SmtpException: The operation has timed out.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at NetProj.EmailDialog.SendEmailMessage() in ...

1 个答案:

答案 0 :(得分:1)

我认为这是System.Net.Mail的着名SSL问题

http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx

如果他们修复了它,那么在框架3.5中不确定4.0。