一、
使用.net自带的mail类
使用时先加载类
imports system.web.mail
定义发送email函数send()
Sub send()
Try
Dim objmailmessage As MailMessage
Dim objmailattachment As MailAttachment
'创建一个附件对象
objmailattachment = New MailAttachment("d:/new.xls")
'创建邮件消息
objmailmessage = New MailMessage
objmailmessage.From = " xylinzai@sohu.com" '发信邮箱
objmailmessage.To = " xylinzai@126.com" '接收邮箱
objmailmessage.Subject = "邮件发送主题"
objmailmessage.Body = "邮件发送内容:测试"
objmailmessage.Attachments.Add(objmailattachment)
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxxx") '邮箱登陆用户名
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxx") '邮箱登陆密码
SmtpMail.SmtpServer = "smtp.sohu.com" '发送服务器
SmtpMail.Send(objmailmessage)
Catch ex As Exception
response.write(ex.Message)
End Try
End Sub
二、 使用系统组件cdosys.dll
实现方法,打开vs2008 菜单"网站"---"添加引用"
确定即可。
定义发送email函数 CDOsendmail()
Sub CDOsendmail()
Try
Dim msg As New CDO.Message
msg.From = " xylinzai@sohu.com"
msg.To = " xylinzai@126.com"
msg.Subject = "邮件主题"
msg.HTMLBody = "<html><body>" + 邮件内容+ "</body></html>"
msg.AddAttachment("d:/test.xls") '新增附件
Dim Config As CDO.IConfiguration = msg.Configuration
Dim ofields As ADODB.Fields = Config.Fields
ofields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2
ofields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value = "xxxxx"
ofields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value = "xxxxxx"
ofields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1
ofields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value = 25
ofields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = "smtp.sohu.com"
ofields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout").Value = 10
ofields.Update()
msg.BodyPart.Charset = "gb2312"
msg.HTMLBodyPart.Charset = "gb2312"
msg.Send()
Response.Write("发送成功")
Catch ex As Exception
response.write(ex.Message)
End Try
End Sub
三、 通过第三方软件jmail
实现方法参考: http://www.vipsos.cn/
使用时先加载类
imports system.web.mail
定义发送email函数send()
Sub send()
Try
Dim objmailmessage As MailMessage
Dim objmailattachment As MailAttachment
'创建一个附件对象
objmailattachment = New MailAttachment("d:/new.xls")
'创建邮件消息
objmailmessage = New MailMessage
objmailmessage.From = " xylinzai@sohu.com" '发信邮箱
objmailmessage.To = " xylinzai@126.com" '接收邮箱
objmailmessage.Subject = "邮件发送主题"
objmailmessage.Body = "邮件发送内容:测试"
objmailmessage.Attachments.Add(objmailattachment)
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxxx") '邮箱登陆用户名
objmailmessage.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxx") '邮箱登陆密码
SmtpMail.SmtpServer = "smtp.sohu.com" '发送服务器
SmtpMail.Send(objmailmessage)
Catch ex As Exception
response.write(ex.Message)
End Try
End Sub
二、 使用系统组件cdosys.dll
实现方法,打开vs2008 菜单"网站"---"添加引用"

确定即可。
定义发送email函数 CDOsendmail()
Sub CDOsendmail()
Try
Dim msg As New CDO.Message
msg.From = " xylinzai@sohu.com"
msg.To = " xylinzai@126.com"
msg.Subject = "邮件主题"
msg.HTMLBody = "<html><body>" + 邮件内容+ "</body></html>"
msg.AddAttachment("d:/test.xls") '新增附件
Dim Config As CDO.IConfiguration = msg.Configuration
Dim ofields As ADODB.Fields = Config.Fields
ofields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2
ofields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value = "xxxxx"
ofields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value = "xxxxxx"
ofields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1
ofields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value = 25
ofields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = "smtp.sohu.com"
ofields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout").Value = 10
ofields.Update()
msg.BodyPart.Charset = "gb2312"
msg.HTMLBodyPart.Charset = "gb2312"
msg.Send()
Response.Write("发送成功")
Catch ex As Exception
response.write(ex.Message)
End Try
End Sub
三、 通过第三方软件jmail
实现方法参考: http://www.vipsos.cn/