所以我试图通过VB.net代码发送电子邮件,我不断收到此错误。我禁用了防火墙,并且在没有从文本框中获取文本时,我可以成功发送电子邮件。我知道当我发送带有1行主体的电子邮件时,它具有正确的设置。发送邮件失败。无法连接到远程服务器。一个套接字操作
Private Sub SendMessage(ByVal SmtpHost As String, ByVal SmtpPort As Integer, ByVal ssl As Boolean, ByVal SmtpUsername As String, ByVal SmtpPassword As String, ByVal mail_from As String, ByVal display_name As String, ByVal Send_To As String, ByVal subject As String, ByVal Body As String, Optional ByVal Attachments As String() = Nothing)
Using smtp As New SmtpClient
smtp.Host = SmtpHost
smtp.Port = SmtpPort
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential(SmtpUsername, SmtpPassword)
smtp.EnableSsl = ssl
Dim message As New MailMessage()
Try
message.From = New MailAddress(mail_from, display_name, System.Text.Encoding.UTF8)
message.To.Add(Send_To)
message.Subject = subject
message.Body = Body
If Attachments IsNot Nothing Then
For Each attachment As String In Attachments
message.Attachments.Add(New Attachment(attachment))
Next
End If
message.ReplyToList.Add(New MailAddress(mail_from))
smtp.Send(message)
Catch ex As Exception
Debug.WriteLine(ex)
End Try
End Using
错误:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network 0.0.0.1:465
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at EmailSender.Form1.Timer2_Tick(Object sender, EventArgs e)
你没有提到你得到的错误...也请澄清这一点,“但是当我在文本框中键入它不只是一条线,可以这样吗?我该如何做到这一点?会发送多行的电子邮件吗?“这没有任何意义...... – Codexer 2015-04-04 03:06:01
我更改了Smtp电子邮件代码,但仍然遇到同样的问题,我更新了错误的问题。 – user3329318 2015-04-04 03:08:25
您有一个计时器正在执行此操作?... – Codexer 2015-04-04 03:24:47