实现发送Email三种方法

时间:2025-02-07 09:33:32
一、 使用.net自带的mail类
使用时先加载类
imports
定义发送email函数send()
Sub send()
        Try
            Dim objmailmessage As MailMessage
            Dim objmailattachment As MailAttachment
            '创建一个附件对象
            objmailattachment = New MailAttachment("d:/")
            '创建邮件消息
            objmailmessage = New MailMessage
             = " xylinzai@" '发信邮箱
             = " xylinzai@" '接收邮箱
             = "邮件发送主题"
             = "邮件发送内容:测试"
            (objmailattachment)
            (" /cdo/configuration/smtpauthenticate", "1")
            (" /cdo/configuration/sendusername", "xxxxxx") '邮箱登陆用户名
            (" /cdo/configuration/sendpassword", "xxxxxx") '邮箱登陆密码
             = "" '发送服务器
            (objmailmessage)
        Catch ex As Exception
            ()
        End Try
    End Sub
二、 使用系统组件
实现方法,打开vs2008 菜单"网站"---"添加引用"

确定即可。
定义发送email函数 CDOsendmail()
Sub CDOsendmail()
        Try
            Dim msg As New
             = " xylinzai@"
             = " xylinzai@"
             = "邮件主题"
             = "<html><body>" + 邮件内容+ "</body></html>"
            ("d:/") '新增附件
            Dim Config As =
            Dim ofields As =
            ofields("/cdo/configuration/sendusing").Value = 2
            ofields("/cdo/configuration/sendusername").Value = "xxxxx"
            ofields("/cdo/configuration/sendpassword").Value = "xxxxxx"
            ofields("/cdo/configuration/smtpauthenticate").Value = 1
            ofields("/cdo/configuration/smtpserverport").Value = 25
            ofields("/cdo/configuration/smtpserver").Value = ""
            ofields("/cdo/configuration/smtpconnectiontimeout").Value = 10
            ()
             = "gb2312"
             = "gb2312"
            ()
            ("发送成功")
        Catch ex As Exception
            ()
        End Try
    End Sub
三、 通过第三方软件jmail
实现方法参考: /