以前仿照书本写了几次代码都只能在自己的电脑发送,传到服务器后会出现 未能访问“CDO.Message”对象。后来知道99%的服务器是不支持mailmessage而支持JMAIL。今天终于鼓起勇气用JMAIL了。
以前用到比较好的支持SMTP验证发件程序:![shades_smile.gif](https://www.cnblogs.com/Emoticons/shades_smile.gif)
Public
Class WebForm2
Class WebForm2
Inherits System.Web.UI.Page
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#Region " Web 窗体设计器生成的代码 "
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'该调用是 Web 窗体设计器所必需的。
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.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
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#End Region
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.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
![InBlock.gif](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")
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
System.Web.Mail.SmtpMail.Send(email)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
End Class
现在用的JMAIL感觉比较好
![14.gif](https://www.cnblogs.com/Emoticons/QQ/14.gif)
。。
Imports
jmail
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public
Class WebForm1
Class WebForm1
Inherits System.Web.UI.Page
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#Region " Web 窗体设计器生成的代码 "
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'该调用是 Web 窗体设计器所必需的。
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.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
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
#End Region
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.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
'在此处放置初始化页的用户代码
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Jmail_Send("admin@vb.net.cn", "fgvub@163.com", "FASDFASDFASD", "通知", "域名受理", "主题测试", "210.51.180.238")
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Sub
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.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
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Dim email As New jmail.Message
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Logging = True
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Silent = True
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.MailServerUserName = "admin@vb.net.cn" 'smtp服务器用户名
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.MailServerPassWord = "xxxxx" 'smtp服务器密码
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.From = fromEmailAddress
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Subject = subject
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.Body = body
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
email.AddRecipient(toEmailAddress)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
If email.Send(MailServer) Then
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Return True
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Else
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Return False
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End If
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Function
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
End Class