email via winsock
Hej!jeg får en fejl 503, hele tiden på mit lille email program. Jeg har taget udgangspunkt i "a simple mailsender" fra www.vbip.com
her er koden:
Private Enum SMTP_State
MAIL_CONNECT
MAIL_HELO
MAIL_FROM
MAIL_RCPTTO
MAIL_DATA
MAIL_DOT
MAIL_QUIT
End Enum
Private Sub CmdTestMail_Click()
Winsock1.Connect Trim$(txtSmtpHost), 25
m_State = MAIL_CONNECT
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strServerResponse As String
Dim strResponseCode As String
Dim strDataToSend As String
'
'Retrieve data from winsock buffer
'
Winsock1.GetData strServerResponse
'
Debug.Print strServerResponse
'
'Get server response code (first three symbols)
'
strResponseCode = Left(strServerResponse, 3)
'
'Only these three codes tell us that previous
'command accepted successfully and we can go on
'
If strResponseCode = "250" Or _
strResponseCode = "220" Or _
strResponseCode = "354" Then
Select Case m_State
Case MAIL_CONNECT
'Change current state of the session
m_State = MAIL_HELO
'
'Remove blank spaces
strDataToSend = Trim$(txtYourEmailAddres)
'
'Retrieve mailbox name from e-mail address
strDataToSend = Left$(strDataToSend, _
InStr(1, strDataToSend, _
"@") - 1)
'Send HELO command to the server
Winsock1.SendData "HELO " & _
strDataToSend & vbCrLf
'
Debug.Print "HELO " & strDataToSend
'
Case MAIL_HELO
'
'Change current state of the session
m_State = MAIL_FROM
'
'Send MAIL FROM command to the server
Winsock1.SendData "MAIL FROM:" & _
Trim$(txtYourEmailAddres) & vbCrLf
'
Debug.Print "MAIL FROM:" & Trim$(txtYourEmailAddres)
'
Case MAIL_FROM
'
'Change current state of the session
m_State = MAIL_RCPTTO
'
'Send RCPT TO command to the server
Winsock1.SendData "RCPT TO:" & _
Trim$(txtRecipientsEmail) & vbCrLf
'
Debug.Print "RCPT TO:" & Trim$(txtRecipientsEmail)
'
Case MAIL_RCPTTO
'
'Change current state of the session
m_State = MAIL_DATA
'
'Send DATA command to the server
Winsock1.SendData "DATA" & vbCrLf
'
Debug.Print "DATA"
'
Case MAIL_DATA
'
'Change current state of the session
m_State = MAIL_DOT
'
'So now we are sending a message body
'Each line of text must be completed with
'linefeed symbol (Chr$(10) or vbLf)
'not with vbCrLf
'
'Send Subject line
Winsock1.SendData "Subject:" & txtSubject & vbLf
'
Debug.Print "Subject:" & txtSubject
'
Dim varLines As Variant
Dim varLine As Variant
'
'Parse message to get lines (for VB6 only)
varLines = Split(txtMessage, vbCrLf)
'
'Send each line of the message
For Each varLine In varLines
Winsock1.SendData CStr(varLine) & vbLf
'
Debug.Print CStr(varLine)
Next
'
'Send a dot symbol to inform server
'that sending of message completed
Winsock1.SendData "." & vbCrLf
'
Debug.Print "."
'
Case MAIL_DOT
'Change current state of the session
m_State = MAIL_QUIT
'
'Send QUIT command to the server
Winsock1.SendData "QUIT" & vbCrLf
'
Debug.Print "QUIT"
Case MAIL_QUIT
'
'Close connection
Winsock1.Close
'
End Select
Else
'
'If we are here server replied with
'unacceptable response code therefore we need
'close connection and inform user about problem
'
Winsock1.Close
'
MsgBox "SMTP Error: " & strServerResponse, _
vbInformation, "SMTP Error"
'
End If
End Sub
'Please pay attention to the strings of the message we're going to send. They don't end with the vbCrLf. We're using vbLf instead. This rule applies to the header of the message (Subject) as well. Surely there are lots of another headers, which differ from Subject. But we're not going to discuss it here. Just remember that each one sends to the server ended by vbLf. Avoiding doing that results in server's misunderstanding the commands you are sending. The last thing you should make is to create the routine, which deals with the Windows Sockets errors.
Private Sub Winsock1_Error(ByVal Number As Integer, _
Description As String, _
ByVal Scode As Long, _
ByVal Source As String, _
ByVal HelpFile As String, _
ByVal HelpContext As Long, _
CancelDisplay As Boolean)
MsgBox "Winsock Error number " & Number & vbCrLf & _
Description, vbExclamation, "Winsock Error"
End Sub
error kode 503 betyder så vidt jeg kan se "bad sequece of commands" Nu er jeg ikke en haj til den slags. Er der nogen der har en ide.
