Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/06/2005, 14:58
alehawk
 
Fecha de Ingreso: junio-2002
Mensajes: 212
Antigüedad: 22 años, 7 meses
Puntos: 0
Yo uso esto:

En modulo:
Imports System.IO
Imports System.Net.Sockets
Imports System.Text

Public Class SocketMail
Private _subject As String
Private _to As String
Private _server As String
Private _port As Integer = 25
Private _body As String
Private _date As Date = Now
Private _from As String
Private _cc As String
Private _bcc As String

Private ns As NetworkStream
Private client As New TcpClient

Public Sub New()
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer)
_server = server
_port = port
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer, _
ByVal from As String, ByVal [to] As String, _
ByVal subject As String, ByVal message As String)
_server = server
_port = port
_from = from
_to = [to]
_subject = subject
_body = message
End Sub

Public Property SMTPServer() As String
Get
Return _server
End Get
Set(ByVal Value As String)
_server = Value
End Set
End Property

Public Property [To]() As String
Get
Return _to
End Get
Set(ByVal Value As String)
_to = Value
End Set
End Property

Public Property From() As String
Get
Return _from
End Get
Set(ByVal Value As String)
_from = Value
End Set
End Property

Public Property CarbonCopy() As String
Get
Return _cc
End Get
Set(ByVal Value As String)
_cc = Value
End Set
End Property

Public Property BlindCarbonCopy() As String
Get
Return _bcc
End Get
Set(ByVal Value As String)
_bcc = Value
End Set
End Property


Public Property Port() As Integer
Get
Return _port
End Get
Set(ByVal Value As Integer)
_port = Value
End Set
End Property

Public Property Message() As String
Get
Return _body
End Get
Set(ByVal Value As String)
_body = Value
End Set
End Property

Public Property SendDate() As Date
Get
Return _date
End Get
Set(ByVal Value As Date)
_date = Value
End Set
End Property

Public Property Subject() As String
Get
Return _subject
End Get
Set(ByVal Value As String)
_subject = Value
End Set
End Property

Public Function Open()
client.Connect(_server, _port)

ns = client.GetStream()

Dim strMessage As String = "HELO TEST" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
End Function

Public Function Close()
Try
Dim strMessage As String = "QUIT" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Catch

End Try

client.Close()
End Function

Public Function Send() As Boolean
Try
Dim response As Integer
Dim strMessage As String

strMessage = "MAIL FROM:" & _from & ControlChars.CrLf & _
"RCPT TO:" & _to & ControlChars.CrLf & _
"DATA" & ControlChars.CrLf & _
"date:" & _date.ToString & ControlChars.CrLf & _
"from:" & _from & ControlChars.CrLf & _
"to:" & _to & ControlChars.CrLf & _
"cc:" & _cc & ControlChars.CrLf & _
"bcc:" & _bcc & ControlChars.CrLf & _
"subject:" & _subject & ControlChars.CrLf & _
_body & ControlChars.CrLf & _
"." & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Finally
client.Close()
End Try

Return True
End Function

End Class


En sub:
Dim m As New SocketMail("smtp.grupofn.com", 25)

With m
m.To = "[email protected]"
m.From = "[email protected]"
m.Subject = "Reporte de Error: " & System.Reflection.Assembly.GetExecutingAssembly.Fu llName
m.Message = TextBox1.Text

m.Open()
m.Send()
m.Close()
End With
MsgBox("El reporte ha sido enviado.", MsgBoxStyle.Information)
__________________
Simuladores y Examenes Cisco, Herramientas de Red Online - Tecnologia y Redes