一段VB.NET代码,生成邮件,发送邮件,支持SMTP验证用户名密码.

可以生成邮件,可以发送邮件,稍做修改就可以写成一个com组件,在ASP里调用.
以后我会整理成一个完整的.


'-------------------------------------------------
'生成基本邮件格式(包括附件),发送邮件到SMTP服务器,
'只能发送到发件人SMTP服务器(需验证),直接投递功能正在编写。
'
'声明:本段代码中,有一部份借签了网上一位大侠的C#代码.由于找不到原文,无法写出原作者名字
'
'代码编写:头太晕
'QQ:2538288
'MSN:[email protected]
'BLOG: http://spaces.msn.com/members/headfaint   http://blog.csdn.net/super852
'-------------------------------------------------
Imports System
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Collections
Namespace eWebMail
    Public Class Mail
        '邮件类,生成基本的邮件格式。访问作者BLOG: http://spaces.msn.com/members/headfaint
        Public Charset As String = "GB2312"
        Public From As String
        Public FromName As String
        Public ReplyTo As String
        Public Subject As String = ""
        Public isHtml As Boolean = False
        Public Body As String = ""
        Public TextBody As String = "This is a HTML mail."
        Public RecipientMaxNum As Integer = 15  '最大收件人数 访问作者BLOG: http://spaces.msn.com/members/headfaint
        Public Recipient As New ArrayList
        Public RecipientCC As New ArrayList
        Public RecipientBCC As New ArrayList
        Protected mPriority As String = "Normal"
        Protected boundary As String = "=====000_eWebMail0099887766554433_====="
        Protected boundary1 As String = "=====001_eWebMail0099887766554433_====="
        Protected Attachments As New ArrayList
        Protected AttachmentsSB As New StringBuilder
        Protected RecipientName As String = ""
        Private Shared fileHT As Hashtable
        Shared Sub New()
            '添加一些常见的文件格式  访问作者BLOG: http://spaces.msn.com/members/headfaint
            fileHT = New Hashtable
            fileHT.Add(".323", "text/h323")
            fileHT.Add(".3g2", "video/3gpp2")
            fileHT.Add(".3gp", "video/3gpp")
            fileHT.Add(".act", "text/xml")
            fileHT.Add(".actproj", "text/plain")
            fileHT.Add(".ai", "application/postscript")
            fileHT.Add(".aif", "audio/aiff")
            fileHT.Add(".aifc", "audio/aiff")
            fileHT.Add(".aiff", "audio/aiff")
            fileHT.Add(".asa", "text/asa")
            fileHT.Add(".asf", "video/x-ms-asf")
            fileHT.Add(".asm", "text/plain")
            fileHT.Add(".asp", "text/asp")
            fileHT.Add(".asx", "video/x-ms-asf")
            fileHT.Add(".au", "audio/basic")
            fileHT.Add(".avi", "video/avi")
            fileHT.Add(".bmp", "image/bmp")
            fileHT.Add(".c", "text/plain")
            fileHT.Add(".cat", "application/vnd.ms-pki.seccat")
            fileHT.Add(".cc", "text/plain")
            fileHT.Add(".cdf", "application/x-netcdf")
            fileHT.Add(".cer", "application/x-x509-ca-cert")
            fileHT.Add(".class", "java/*")
            fileHT.Add(".cod", "text/plain")
            fileHT.Add(".cpp", "text/plain")
            fileHT.Add(".crl", "application/pkix-crl")
            fileHT.Add(".crt", "application/x-x509-ca-cert")
            fileHT.Add(".cs", "text/plain")
            fileHT.Add(".css", "text/css")
            fileHT.Add(".cxx", "text/plain")
            fileHT.Add(".dbs", "text/plain")
            fileHT.Add(".def", "text/plain")
            fileHT.Add(".der", "application/x-x509-ca-cert")
            fileHT.Add(".dib", "image/bmp")
            fileHT.Add(".dll", "application/x-msdownload")
            fileHT.Add(".doc", "application/msword")
            fileHT.Add(".dot", "application/msword")
            fileHT.Add(".dps", "interface/vnd.divx-skin")
            fileHT.Add(".dsp", "text/plain")
            fileHT.Add(".dsw", "text/plain")
            fileHT.Add(".dxu", "video/vnd.divx-playlist")
            fileHT.Add(".edn", "application/vnd.adobe.edn")
            fileHT.Add(".eml", "message/rfc822")
            fileHT.Add(".eps", "application/postscript")
            fileHT.Add(".etd", "application/x-ebx")
            fileHT.Add(".etp", "text/plain")
            fileHT.Add(".exe", "application/x-msdownload")
            fileHT.Add(".ext", "text/plain")
            fileHT.Add(".fdf", "application/vnd.fdf")
            fileHT.Add(".fif", "application/fractals")
            fileHT.Add(".fky", "text/plain")
            fileHT.Add(".gif", "image/gif")
            fileHT.Add(".h", "text/plain")
            fileHT.Add(".hpp", "text/plain")
            fileHT.Add(".hqx", "application/mac-binhex40")
            fileHT.Add(".hta", "application/hta")
            fileHT.Add(".htc", "text/x-component")
            fileHT.Add(".htm", "text/html")
            fileHT.Add(".html", "text/html")
            fileHT.Add(".htt", "text/webviewhtml")
            fileHT.Add(".htx", "text/html")
            fileHT.Add(".hxx", "text/plain")
            fileHT.Add(".i", "text/plain")
            fileHT.Add(".ico", "image/x-icon")
            fileHT.Add(".idl", "text/plain")
            fileHT.Add(".iii", "application/x-iphone")
            fileHT.Add(".inc", "text/plain")
            fileHT.Add(".inl", "text/plain")
            fileHT.Add(".ins", "application/x-internet-signup")
            fileHT.Add(".isp", "application/x-internet-signup")
            fileHT.Add(".java", "java/*")
            fileHT.Add(".jfif", "image/jpeg")
            fileHT.Add(".jpe", "image/jpeg")
            fileHT.Add(".jpeg", "image/jpeg")
            fileHT.Add(".jpg", "image/jpeg")
            fileHT.Add(".js", "application/x-javascript")
            fileHT.Add(".kci", "text/plain")
            fileHT.Add(".latex", "application/x-latex")
            fileHT.Add(".lgn", "text/plain")
            fileHT.Add(".ls", "application/x-javascript")
            fileHT.Add(".lst", "text/plain")
            fileHT.Add(".m1v", "video/mpeg")
            fileHT.Add(".m3u", "audio/x-mpegurl")
            fileHT.Add(".mak", "text/plain")
            fileHT.Add(".man", "application/x-troff-man")
            fileHT.Add(".map", "text/plain")
            fileHT.Add(".mdb", "application/msaccess")
            fileHT.Add(".mfp", "application/x-shockwave-flash")
            fileHT.Add(".mht", "message/rfc822")
            fileHT.Add(".mhtml", "message/rfc822")
            fileHT.Add(".mid", "audio/mid")
            fileHT.Add(".midi", "audio/mid")
            fileHT.Add(".mk", "text/plain")
            fileHT.Add(".mocha", "application/x-javascript")
            fileHT.Add(".movie", "video/x-sgi-movie")
            fileHT.Add(".mp2", "video/mpeg")
       

你可能感兴趣的:(VB.NET学习,vb.net,string,function,blog,integer,exception)