邮件发送、接收.net开源组件

时间:2006/4/18 16:31:54      阅读:3968          

      很多朋友们都想自己做邮件管理,找些东西出来给大家了,很久以前就用过的组件了,可能有很多人没用过,非常不错,拿出来共享给大家吧,先介绍一下组件的功能吧。

OpenSMTP.NET简介:OpenSMTP.NET是使用纯C#开发的、功能齐全的邮件发送组件,应用低层的TCPClient,不依赖.NET的Mail类,支持所有标准MIME协议,支持的特性包括:嵌入式图片、任意多附件、任意文字编码,还支持QP和BASE64内容编码。开源站点:http://sourceforge.net/projects/opensmtp-net/,所有代码和新版公布都在里面了,还带有实例,自己去下载研究吧。

OpenPOP.NET简介:OpenPOP.NET是使用C#开发的邮件接收组件,包括核心的MIME解析器,支持任何语言编码、QP和BASE64内容解码、任意多附件的解析、Text/HTML格式的解析,拥有操作事件,额外地还可以解析由IE保存的MHTML文件,额外地还包括了一个功能齐全的邮件接收客户端。开源站点:http://sourceforge.net/projects/hpop,所有代码和新版公布都在里面。

想自己做邮件系统的朋友们去下载吧。

发送代码:

以下是代码片段:

 

    Public Sub SubmitBtn_Click(ByVal sender As Object, ByVal E As EventArgs)

        Try
            'SMTP服务器
            Dim smtpHost As String = "smtp.163.com"
            'SMTP服务器端口
            Dim smtpPort As Integer = 25
            '邮箱用户名
            Dim smtpUsername As Integer = "username"
            '邮箱密码
            Dim smtpPwd As Integer = "*******"
            '临时文件夹(保存要发送的附件)
            Dim tempDir As String = "C:\\Inetpub\\wwwroot\\openSmtp"
            '发送者邮件地址
            Dim senderEmail As String = Request.Form.Get("from")
            '接收者邮件地址
            Dim recipientEmail As String = Request.Form.Get("to")
            '发送主题
            Dim subject As String = Request.Form.Get("subject")
            '发送内容
            Dim body As String = Request.Form.Get("body")


            Message.InnerHtml = Nothing
            Message.Style("visibility") = "show"

            SmtpConfig.VerifyAddresses = False

            Dim msg As MailMessage = New MailMessage(senderEmail, recipientEmail)
            ' 这行一定要填上,不然收到的中文邮件是一连串的???????
            msg.Charset = "gb2312"
            msg.Subject = subject
            msg.Body = body

            Dim smtp As Smtp = New Smtp(smtpHost, smtpUsername, smtpPwd, smtpPort)
            smtp.SendMail(msg)

            Dim toList As StringBuilder = New StringBuilder
            Dim i As IEnumerator
  For  i = msg.To.GetEnumerator() To i.MoveNext()- 1  Step
                Dim a As EmailAddress = CType(i.Current, EmailAddress)
                toList.Append(a.Address + ";")
            Next

            Message.InnerHtml += "<b>SendMail Results:</b><br>"
            Message.InnerHtml += "To:" + toList + "<br>"
            Message.InnerHtml += "From:" + msg.From.Address + "<br>"
            Message.InnerHtml += "Subject:" + msg.Subject + "<br>"
            Message.InnerHtml += "Body:" + msg.Body + "<br>"

        Catch mfa As MalformedAddressException
            '异常处理
            Message.InnerHtml += "Address error occured: " + mfa.Message
        Catch se As SmtpException
            '异常处理
            Message.InnerHtml += "Smtp error occured: " + se.Message
        Catch e As Exception
            '异常处理
            Message.InnerHtml += "Error occured: " + e.Message + "r\n" + e
        End Try

    End Sub

评论
  • Re:邮件发送、接收.net开源组件  (2006/4/19 17:45:42) by 长风 
    它里面那例子,几行代码都没有的.晕!
  • Re:邮件发送、接收.net开源组件  (2006/4/19 19:18:07) by Wintalen 
    前面没有定义Message对象,却突然冒出一句Message.InnerHtml = Nothing来,让人不解。
  • Re:邮件发送、接收.net开源组件  (2006/8/16 13:42:05) by 飘萍 
        还有没有别的比较好的开源组件,站长多介绍些。
  • Re:邮件发送、接收.net开源组件  (2006/9/26 9:49:14) by 800tom 
        有没有C#的示例啊?
标 题:
 
姓 名:
 
主 页:

验证码:

评论:
 

Because of the cache,you may see your comments several minutes later.