几种不同的邮件发送解决方案

几种不同的邮件发送解决方案

    Private Sub Send()
        Dim outObj As New Outlook.Application()
        Dim Item As Outlook.MailItemClass
        Item = outObj.CreateItem(0)
        Item.To = "lihonggen0@163.com "
        Item.Subject = "hello"
        Item.Body = "hell"
        Item.Attachments.Add("C:/abc.txt")
        Item.Send()
End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mailObj As New MailMessage()
        Dim smtp As SmtpMail
        '定义SMTP服务器的名称 
        smtp.SmtpServer = "smtp.XXX.com"
        '定义邮件的发送地址 
        mailObj.From = "lihonggen@XXX.com"
        '定义邮件的接收地址 
        mailObj.To = " AAA@XXX.com"
        '定义邮件的暗送地址 
        mailObj.Bcc= "aa@sina.com"
        '定义邮件的抄送地址 
        mailObj.Cc = "aaa@sina.com"
        '定义邮件的主题 
        mailObj.Subject = "主题"
        '定义邮件的主体 
        mailObj.Body = "邮件主体!"
        '邮件以 HTML的格式发送 
        mailObj.BodyFormat = MailFormat.Html
        '定义邮件的有限级,在此设定为高 
        mailObj.Priority = MailPriority.High
        '给发送的邮件附加上一个附件 
        mailObj.Attachments.Add(New MailAttachment("c:/aa.doc"))
        smTp.Send(mailObj)
    End Sub
        Dim sendData As String
        Dim szData As Byte()
        Dim CRLF As String
        CRLF = "/r/n"

        '创建与服务器25端口的连接
        Dim SmtpServ As New TcpClient(txtsmtp.Text, 25)
        lstlog.Items.Clear()

        '显示服务器初始信息
        Dim NetStrm As NetworkStream
        NetStrm = SmtpServ.GetStream()

        Dim RdStrm As New StreamReader(SmtpServ.GetStream())
        If RdStrm.ReadLine() <> "" Then lstlog.Items.Add(RdStrm.ReadLine())
        '
        sendData = "HELO server " + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '标志发件人
        sendData = "MAIL FROM: " + "<" + txtfrom.Text + ">" + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '标志收件人
        sendData = "RCPT TO: " + "<" + txtTo.Text + ">" + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '准备发送内容
        sendData = "DATA " + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '发送主题
        sendData = "SUBJECT: " + txtsub.Text + CRLF
        '发送内容
        sendData = sendData + txtmsg.Text + CRLF

        '结束发送
        sendData = sendData + "." + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '退出
        sendData = "QUIT " + CRLF
        szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
        NetStrm.Write(szData, 0, szData.Length)
        lstlog.Items.Add(RdStrm.ReadLine())

        '关闭连接
        NetStrm.Close()
        RdStrm.Close()
        lstlog.Items.Add("连接关闭")
        lstlog.Items.Add("发送成功")
        Mymail = CreateObject("CDONTS.NewMail")
        Mymail.From = *** '信件发送者信箱
        Mymail.To = *** ‘信件接收者信箱
        Mymail.CC = *** '抄送
        Mymail.BCC = *** ’密件发送
        Mymail.Subject = *** ‘信件主题
        Mymail.Body = *** ’信件正文
        '设置优先级,0-不重要,1-一般,2-重要。
        Mymail.Importance = 2
        Mymail.Send()
        Mymail = Nothing
        Dim JMail
        JMail = Server.CreateObject("JMail.SMTPMail")
        JMail.Logging = True
        JMail.ServerAddress = "202.96.144.48"
        JMail.Sender = "lihonggen0@163.com"
        JMail.Subject = "subject."
        JMail.Body = "body."
        JMail.AddRecipient("bbbb@163.com")
        JMail.AddAttachment("c:/go.gif")
        JMail.Priority = 3
        JMail.Execute()
        JMail = Nothing


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=557929

阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭