Option Explicit
Private timer As Long
Private data As Boolean
Private inder As Boolean
Dim inData As String
Private Sub Command1_Click()
smtp.LocalPort = 0 '设置本地使用的端口
smtp.Protocol = sckTCPProtocol '设置Winsock控件使用的协议,TCP或UDP。
smtp.RemoteHost = "smtp.163.com" '设置发送Email的服务器
smtp.RemotePort = 25 '设置要连接的远程端口号
smtp.Connect
End Sub
Private Sub smtp_Connect()
While Not inder 'Wait for reply /While 条件 Wend 只要指定的条件为 True,则会重复执行While和Wend之间的语句
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
Dim reply As String
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 220 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
smtp.SendData "HELO smtp.163.com" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
'''''''''''''''''''''''''''''''''''''''''''''
'-----------------AUTH 登录---------
smtp.SendData "AUTH LOGIN" & vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 334 Then
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
'发送名字
smtp.SendData "bXlkbmZ6aGFuZ2hhb0AxNjMuY29t" & vbCrLf
'发送密码
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 334 Then
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
smtp.SendData "bXlkbmZtaW1h" & vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData
inData = ""
If Not reply = 235 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
''''''''''''''''''''''''''''''''''''''''''''
smtp.SendData "MAIL FROM:<mydnfzhanghao@163.com>" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData "RCPT TO:<21818113@qq.com>" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData '目前到此处是正常的该程序
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData ("data " & vbCrLf)
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData
inData = ""
If Not reply = 354 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData ("quit" & vbCrLf)
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 221 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
End Sub
Private Sub Smtp_DataArrival(ByVal bytesTotal As Long)
Dim data As String
smtp.GetData data, vbString
inData = inData + data
'''''''''''''''''''''''''''''''''''''''''''''
If Len(inData) <> 0 Then
inder = True
End If
End Sub
Option Explicit
Private timer As Long
Private data As Boolean
Private inder As Boolean
Dim inData As String
Private Sub Command1_Click()
smtp.LocalPort = 0 '设置本地使用的端口
smtp.Protocol = sckTCPProtocol '设置Winsock控件使用的协议,TCP或UDP。
smtp.RemoteHost = "smtp.163.com" '设置发送Email的服务器
smtp.RemotePort = 25 '设置要连接的远程端口号
smtp.Connect
End Sub
Private Sub smtp_Connect()
While Not inder 'Wait for reply /While 条件 Wend 只要指定的条件为 True,则会重复执行While和Wend之间的语句
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
Dim reply As String
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 220 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
smtp.SendData "HELO smtp.163.com" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
'''''''''''''''''''''''''''''''''''''''''''''
'-----------------AUTH 登录---------
smtp.SendData "AUTH LOGIN" & vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 334 Then
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
'发送名字
smtp.SendData "bXlkbmZ6aGFuZ2hhb0AxNjMuY29t" & vbCrLf
'发送密码
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 334 Then
MsgBox "Server returned the following error:" + vbCrLf + reply
Exit Sub
End If
smtp.SendData "bXlkbmZtaW1h" & vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData
inData = ""
If Not reply = 235 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
''''''''''''''''''''''''''''''''''''''''''''
smtp.SendData "MAIL FROM:<mydnfzhanghao@163.com>" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
' MsgBox inData
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData "RCPT TO:<21818113@qq.com>" + vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
MsgBox inData '目前到此处是正常的该程序
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData "data " & vbCrLf
While Not inder 'Wait for reply
If smtp.State = sckClosed Then Exit Sub
DoEvents
Wend
inder = False
reply = Val(Left$(inData, 3))
'MsgBox inData
inData = ""
If Not reply = 354 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 250 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
smtp.SendData "quit" & vbCrLf
inder = False
reply = Val(Left$(inData, 3))
inData = ""
If Not reply = 221 Then 'Error occured
MsgBox "Server returned the following error:" + vbCrLf + reply
End If
End Sub
Private Sub Smtp_DataArrival(ByVal bytesTotal As Long)
Dim data As String
smtp.GetData data, vbString
inData = inData + data
'''''''''''''''''''''''''''''''''''''''''''''
If Len(inData) <> 0 Then
inder = True
End If
End Sub