通过雅虎发送电子邮件 [英] Sending EMail via Yahoo
问题描述
我正试图通过雅虎从我的代码发送一封电子邮件。
我已经建立了一个类来完成这个。
类标题声明:
I am trying to send an email message from my code via Yahoo.
I have built a class to accomplish this.
The class header declares:
Dim mEMail As New MailMessage()
Dim SmtpServer As New SmtpClient()
新的分类是:
The class new sub is:
Public Sub New()
MyBase.New()
SmtpServer.Host = "smtp.mail.yahoo.com"
SmtpServer.Port = 465
SmtpServer.Credentials = New Net.NetworkCredential("<username>", "<mpassword>")
End Sub
班级中的发送命令是:
The send command in the class is:
' send the message
Public Function Send() As Boolean
Send = False
If mToAddr = "" Then Exit Function
If Body = "" Then Exit Function
mEMail.To.Add(ToAddr)
mEMail.From = New MailAddress("software@bellalunabeverages.com")
mEMail.Subject = mSubject
mEMail.Body = mHeader & vbCrLf & mBody & vbCrLf & vbCrLf & mFooter
If AttachList.Count > 0 Then
For i As Short = 0 To AttachList.Count - 1 Step 1
mEMail.Attachments.Add(New Net.Mail.Attachment(AttachList(i).Trim))
Next i
End If
Try
SmtpServer.Send(mEMail)
Send = True
Catch ex As Exception
'Console.WriteLine(ex.ToString)
MsgBox("Error occured during email send " & vbCrLf & _
"ERROR: " & ex.ToString)
Send = False
End Try
End Function
抛出的异常是:
错误! System.Net.Mail.Smtpexception:发送邮件失败---> System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接。 ....
这个问题的解决办法是什么?
The exception that gets thrown is:
ERROR! System.Net.Mail.Smtpexception: Failure sending mail ---> System.IO.IOException: Unable to read data from thye transport connection: an existing connection was forcibly closed by the remote host. ....
What is the solution to this problem?
推荐答案
您是否添加了参考文献? System.Net.Mail ??
Have you added the reference System.Net.Mail??
当前代码出现问题
System.Net.Mail.SmtpClient
不支持端口465。
您应该使用端口587 withEnableSsl = false
。
因此,代码通常如下所示......
Problem with the current code
Port 465 isn''t supported bySystem.Net.Mail.SmtpClient
.
You should go with Port 587 withEnableSsl = false
.
So,the code will typically look like below...
Public Sub New()
MyBase.New()
SmtpServer.Host = "smtp.mail.yahoo.com"
SmtpServer.Port = 587
SmtpServer.Credentials = New Net.NetworkCredential("<username>", "<mpassword>")
SmtpServer.EnableSsl = false
End Sub
注意
- > 发送()功能将相同。
- >确保yahoo用户名(<用户名>)和密码(< mpassword>)有效。
谢谢......
NOTE
-> Send() function will be the same.
-> Make sure that yahoo username("<username>") and password("<mpassword>") are valid.
Thanks...
这篇关于通过雅虎发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!