Has anyone used WinSock to send Email?
I found a page that told me how, but it doesn't show how to send login/password information and my SMTP server requires login.
Anyone Know How?
This is how I connect:
Code:
With frmMain.WinSock1
If .State = sckClosed Then ' Check to see if socket is closed
DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
first = "mail from: " & FromEmailAddress & vbCrLf ' Get who's sending E-Mail address
Second = "rcpt to: " & ToEmailAddress & vbCrLf ' Get who mail is going to
Third = "Date: " & DateNow & vbCrLf ' Date when being sent
Fourth = "From: """ & FromName & """ <" & FromEmailAddress & ">" + vbCrLf ' Who's Sending
Fifth = "To: " & ToNametxt & vbCrLf ' Who it going to
Sixth = "Subject: " & EmailSubject & vbCrLf ' Subject of E-Mail
Seventh = EmailBodyOfMessage & vbCrLf ' E-mail message body
Ninth = "X-Mailer: Web Alarm" & vbCrLf ' What program sent the e-mail, customize this
.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail per program start
.protocol = sckTCPProtocol ' Set protocol for sending
.RemoteHost = MailServerName ' Set the server address
.RemotePort = 25 ' Set the SMTP Port
.Connect ' Start connection
WaitFor ("220")
frmMain.Caption = "Connecting...."
.SendData ("HELO EnterComputerNameHere" & vbCrLf)
WaitFor ("250")
frmMain.Caption = "Connected"
.SendData (first)
frmMain.Caption = "Sending Message"
WaitFor ("250")
.SendData (Second)
WaitFor ("250")
.SendData ("data" & vbCrLf)
WaitFor ("354")
.SendData (Fourth & Third & Ninth & Fifth & Sixth & vbCrLf)
.SendData (Seventh & vbCrLf)
.SendData ("." & vbCrLf)
WaitFor ("250")
.SendData ("quit" & vbCrLf)
frmMain.Caption = "Disconnecting"
WaitFor ("221")
.Close
Else
MsgBox (Str(.State))
End If
End With
Code:
Public Sub WaitFor(ResponseCode As String)
Start = frmMain.Timer2 ' Time event so won't get stuck in loop
While Len(Response) = 0
Tmr = Start - frmMain.Timer2
DoEvents ' Let System keep checking for incoming response **IMPORTANT**
If Tmr > 50 Then ' Time in seconds to wait
MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
Exit Sub
End If
Wend
While Left(Response, 3) <> ResponseCode
DoEvents
If Tmr > 50 Then
MsgBox "SMTP service error, impromper response code. Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
Exit Sub
End If
Wend
Response = "" ' Sent response code to blank **IMPORTANT**
End Sub
The process always Hangs, I'm thinking it is because I'm not logging into the server.
any ideas?