您的位置:建站学院首页 >> 文章 >> asp.net >> VB.Net语言
一个不需要CDO和IIS发送邮件的例子
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
Private Sub SendText(ByVal strMsg As String)
Dim sendBytes As [Byte]()
If Not ExtendedASCIIEncode(strMsg, sendBytes) Then
Err.Raise(vbObjectError + 1, "SendText", "Error en el Byte-Array!")
Exit Sub
End If
networkStream.Write(sendBytes, 0, sendBytes.Length)
End Sub
Private Function GetResponse() As String
Dim Start As Double
Dim Tmr As Double
Dim bytes() As Byte
Start = Now.TimeOfDay.TotalSeconds
ReDim bytes(tcpClient.ReceiveBufferSize)
While Not networkStream.DataAvailable
Tmr = Now.TimeOfDay.TotalSeconds - Start
Application.DoEvents()
If Tmr > m_iTimeOut Then
GetResponse = "TIMEOUT!"
Exit Function
End If
End While
If networkStream.DataAvailable Then
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
GetResponse = Encoding.ASCII.GetString(bytes)
Else
GetResponse = "TIMEOUT!"