Hi,
I have a program that sends mail to an smtp server using a network
stream and smtp commands. If you just want a socket connection to a
server and know what commands to send then this could probably be
modified for your needs.
Option Explicit On
Option Strict On
Imports System.IO
Imports System.Net
Imports System.Net.Sock ets
Module SendMail
Dim NetStrm As NetworkStream
Public Sub GenerateMail(By Val User As String)
Dim localName As String = System.Environm ent.MachineName
Dim UserMail As String = User & "@foo.edu"
Dim TheDate As String = CType(Now(), String)
Try
Dim reader As StreamReader
Dim buffer As String
Dim SmtpClient As New TcpClient
SmtpClient.Conn ect("smtpserver .foo.edu", 25)
NetStrm = SmtpClient.GetS tream()
reader = New StreamReader(Sm tpClient.GetStr eam())
buffer = reader.ReadLine ()
SendCommand("HE LO " & UserMail)
buffer = reader.ReadLine ()
SendCommand("MA IL FROM:" & UserMail)
buffer = reader.ReadLine
SendCommand("RC PT TO:" & UserMail)
buffer = reader.ReadLine
SendCommand("DA TA")
buffer = reader.ReadLine
SendCommand("Su bject: Some Subject")
SendCommand("FR OM:" & UserMail)
SendCommand("DA TE:" & TheDate)
SendCommand("TO :" & UserMail)
SendCommand("So me message text")
SendCommand(vbC rLf)
SendCommand(vbC rLf)
SendCommand("So me message text")
SendCommand("So me message text")
SendCommand(vbC rLf)
SendCommand("So me message text")
SendCommand("So me message text")
SendCommand(vbC rLf)
SendCommand("So me message text")
SendCommand(vbC rLf)
SendCommand(vbC rLf)
SendCommand(vbC rLf & ".")
buffer = reader.ReadLine
'MsgBox(buffer)
SendCommand("QU IT")
buffer = reader.ReadLine
'MsgBox(buffer)
NetStrm.Close()
reader.Close()
SmtpClient.Clos e()
buffer = Nothing
Catch ex As Exception
MsgBox(ex.Messa ge & vbCrLf & ex.Source)
End Try
End Sub
Private Sub SendCommand(ByV al text As String)
Dim szData() As Byte
text = text & vbCrLf
szData = System.Text.Enc oding.ASCII.Get Bytes(text.ToCh arArray)
NetStrm.Write(s zData, 0, szData.Length)
End Sub
End Module
Gita George wrote:
I'm trying to write an application that connects to a mail server on port
110 and uses POP3 commands to check if I have any new mail.
It's that simple.
That same application on VB 6 was focused on the DataArrival event of
Winsock control.
I was sending commands and when I received the results I would analyze that.
Thanks.
"Gita George" <ge****@vital-heyl.com> wrote in message
news:uD******** ******@TK2MSFTN GP11.phx.gbl...
I'm trying to write a program (a pop3 mail checker) and I'm having a
problem.
I'm using the socket control and I've noticed that I do not have any
events
!?
How do I use the socket to receive data?
How do I simulate the DataArrival event from Winsock (VB 6.0)?
How can I create and alternate event?
This also is the case for the tcpClient control.
If you have any solution please tell me if they can be applied to the
tcpClient control.
Any input would be apreciated
Thanks in advance ...