winsock发邮件怎么实现用代理(IP)发?搜了下一点资料都没有
winsock发邮件怎么实现用代理发?
[解决办法]
去搜索一下 HTTP 代理,然后你可以自己抓包看,其实很简单的,就是开始与其进行 HTTP 协议通讯,之后就没什么区别了,如:
Dim SendData() As Byte
Dim ConnectOver As Boolean
'...
Private Sub GoGoGo()
ConnectOver = False
If ProxyType = 0 Then
Winsock1.Connect RemoteHost, RemotePort
Else
Winsock1.Connect ProxyHost, ProxyPort
End If
End Sub
'...
Private Sub Winsock1_Connect()
If ProxyType = 0 or (ProxyType = 0 And ConnectOver = True) Then
'正常连接方式
ConnectOver = True
Winsock1.SendData SendData
Else
'代理网络连接方式
Dim SendString As String
SendString = ""
If RemotePort = 80 Then
SendString = "CONNECT " & RemoteHost & " HTTP/1.1" & vbCrLf
Else
SendString = "CONNECT " & RemoteHost & ":" & RemotePort & " HTTP/1.1" & vbCrLf
End If
If Len(ProxyUser) > 0 Or Len(ProxyPass) > 0 Then
'使用代理账号和密码登陆,这里是进行 MIME 的 base64 编码用户信息
SendString = SendString & "Proxy-Authorization: Basic " & Codeing.StrToMIME(ProxyUser & ":" & ProxyPass) & "==" & vbCrLf
End If
SendString = SendString & "Accept: */*" & vbCrLf
SendString = SendString & "Content-Type: text/html" & vbCrLf
SendString = SendString & "Proxy-Connection: Keep-Alive" & vbCrLf
If ProxyDomain <> "" Then
SendString = SendString & "Host: " & ProxyDomain & vbCrLf
End If
SendString = SendString & "Content-length: 0" & vbCrLf & vbCrLf
Winsock1.SendData SendString
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strBuff As String
If bytesTotal = 0 Then
Winsock1_Close '调用 Close 事件里的断开处理过程
Exit Sub
End If
If ConnectOver = False Then
Winsock1.GetData strBuff, vbString, bytesTotal
If UCase(Left(strBuff, 12)) = "HTTP/1.0 200" Then
'这里执行正常应该在 Connect 事件中发送的数据,因为改变了 ConnectOver 标志再出发一次这个过程
ConnectOver = True
Winsock1_Connect
Else
'代理服务器连接失败
Winsock1_Close '调用 Close 事件里的断开处理过程
End If
Else
' 到这里说明代理连接已经成功,这里就和平时一样处理就可以了
'...
End If
End Sub
Private Sub Winsock1_Close()
If Winsock1.State <> 0 Then Winsock1.Close
End Sub