asp.net实现发送Email三种方法

一、 使用.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/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值