以前仿照书本写了几次代码都只能在自己的电脑发送,传到服务器后会出现 未能访问“CDO.Message”对象。后来知道99%的服务器是不支持mailmessage而支持JMAIL。今天终于鼓起勇气用JMAIL了。
以前用到比较好的支持SMTP验证发件程序:![](https://www.cnblogs.com/Emoticons/shades_smile.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Class WebForm2Class WebForm2
Inherits System.Web.UI.Page
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#Region " Web 窗体设计器生成的代码 "
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'该调用是 Web 窗体设计器所必需的。
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#End Region
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim email As New System.Web.Mail.MailMessage
email.To = "xxb@263.net"
email.From = "xx@xx.xx"
email.Body = "BODY"
email.Subject = "SUBJECT"
email.BodyFormat = Web.Mail.MailFormat.Text
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
'将以下三行中中的,第2个参数,设为你的smtp相应值,即可
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "210.51.180.238")
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "XXXX")
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "XXXX")
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
System.Web.Mail.SmtpMail.Send(email)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
End Class
现在用的JMAIL感觉比较好
![](https://www.cnblogs.com/Emoticons/QQ/14.gif)
。。
Imports jmail
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Class WebForm1Class WebForm1
Inherits System.Web.UI.Page
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#Region " Web 窗体设计器生成的代码 "
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'该调用是 Web 窗体设计器所必需的。
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#End Region
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Jmail_Send("admin@vb.net.cn", "fgvub@163.com", "FASDFASDFASD", "通知", "域名受理", "主题测试", "210.51.180.238")
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Function Jmail_Send()Function Jmail_Send(ByVal fromEmailAddress As String, ByVal toEmailAddress As String,
ByVal ccEmailAddress As String,
ByVal bccEmailAddress As String,
ByVal subject As String, ByVal body As String, ByVal MailServer
As String) As Boolean
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Dim email As New jmail.Message
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Logging = True
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Silent = True
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.MailServerUserName = "admin@vb.net.cn" 'smtp服务器用户名
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.MailServerPassWord = "xxxxx" 'smtp服务器密码
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.From = fromEmailAddress
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Subject = subject
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Body = body
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.AddRecipient(toEmailAddress)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
If email.Send(MailServer) Then
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Return True
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Else
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Return False
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End If
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Function
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Class
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)