一个不需要CDO和IIS发送邮件的例子

来源:aspcool 作者: 2007-03-30 出处:pcdog.com

.net  iis  msn  office  
下一页 1 2 3 

    下面的例子是转载国外的,可以实现不使用CDO和IIS发送邮件。说明:本例子没有经过测试,原地址在:
  http://www.dotnetforums.net/t81508.html
  
  
  VB.NET:
  

  
  --------------------------------------------------------------------------------
  Imports System
  Imports System.Text
  Imports System.Windows.Forms
  Public Class cSMTP
   Private m_sSender As String
   Private m_sUser As String
   Private m_sSenderName As String
   Private m_sRecipient As String
   Private m_sRecipientName As String
   Private m_sServer As String
   Private m_iPort As Integer
   Private m_sSubject As String
   Private m_sBody As String
  
   Private m_iTimeOut As Integer
   Private m_colCC As Collection
   Private m_colCC_OK As Collection
  
   Private Structure TRecipient
   Dim strEMail As String
   Dim strName As String
   Dim bBlind As Boolean
   End Structure
  
   Private tcpClient As System.Net.Sockets.TcpClient
   Private networkStream As System.Net.Sockets.NetworkStream
  
   Public Property Timeout() As Integer
   Get
   Timeout = m_iTimeOut
   End Get
   Set(ByVal Value As Integer)
   m_iTimeOut = Value
   End Set
   End Property
  
   Public Property User() As String
   Get
   User = m_sUser
   End Get
   Set(ByVal s As String)
   m_sUser = s
   End Set
   End Property
  
   Public Property Subject() As String
   Get
   Subject = m_sSubject
   End Get
   Set(ByVal s As String)
   m_sSubject = s
   End Set
   End Property
  
   Public Property Body() As String
   Get
   Body = m_sBody
   End Get
   Set(ByVal s As String)
   m_sBody = s
   End Set
   End Property
  
   Public Property Sender() As String
   Get
   Sender = m_sSender
   End Get
   Set(ByVal s As String)
   m_sSender = s
   End Set
   End Property
  
   Public Property SenderName() As String
   Get
   SenderName = m_sSenderName
   End Get
   Set(ByVal s As String)
   m_sSenderName = s
   End Set
   End Property
  
   Public Property Recipient() As String
   Get
   Recipient = m_sRecipient
   End Get
   Set(ByVal s As String)
   m_sRecipient = s
   End Set
   End Property
  
   Public Property RecipientName() As String
   Get
   RecipientName = m_sRecipientName
   End Get
   Set(ByVal s As String)
   m_sRecipientName = s
   End Set
   End Property
  
   Public Property Server() As String
   Get
   Server = m_sServer
   End Get
   Set(ByVal s As String)
   m_sServer = s
   End Set
   End Property
  
   Public Property Port() As Integer
   Get
   Port = m_iPort
   End Get
   Set(ByVal i As Integer)
   m_iPort = i
   End Set
   End Property
  
   Private Sub Init()
   m_sBody = ""
   m_sSubject = ""
   m_sSender = ""
   m_sSenderName = ""
   m_sRecipient = ""
   m_sRecipientName = ""
   m_sServer = ""
   m_iPort = -1
   m_iTimeOut = 30
  
   CloseCon()
   tcpClient = New System.Net.Sockets.TcpClient
  
   m_colCC = New Collection
   m_colCC_OK = New Collection
   End Sub
  
   Private Function ExtendedASCIIEncode(ByVal strMsg As String, ByRef arrByte() As Byte) As Boolean
   Dim i As Integer
  
   Try
   ReDim arrByte(strMsg.Length - 1)
   For i = 0 To strMsg.Length - 1
   arrByte(i) = CByte(Asc(strMsg.Substring(i, 1)))
   Next i
  
   ExtendedASCIIEncode = True
   Catch ex As Exception
   If i > 0 Then
   ReDim Preserve arrByte(i - 1)
   End If
   ExtendedASCIIEncode = False
   End Try
   End Function
  


更多内容请看PCdog.com--垃圾邮件专题
下一页 1 2 3 
上一篇:关于C#静态构造函数的几点说明
下一篇:在VB.NET中利用Split和Replace函数计算