'我用winsock发邮件
  '代码:---------------------------------------------------
Option Explicit
Private timer As Long
Private data As Boolean
Private inder As Boolean
Dim inData As StringPrivate Sub Command1_Click()
smtp.LocalPort = 0 '设置本地使用的端口
smtp.Protocol = sckTCPProtocol '设置Winsock控件使用的协议,TCP或UDP。
smtp.RemoteHost = "smtp.163.com" '设置发送Email的服务器
smtp.RemotePort = 25 '设置要连接的远程端口号
smtp.Connect
End SubPrivate Sub smtp_Connect()
While Not inder         'Wait for reply        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
'''''''''''''''''''''''''''''''''''''''''''''
smtp.SendData "noop" + 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
''''''''''''''''''''''''''''''''''''''''''''
     smtp.SendData "MAIL FROM:<[email protected]>" + 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
   smtp.SendData "RCPT TO:<[email protected]>" + 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
    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))
    inData = ""
        If Not reply = 354 Then           'Error occured
        MsgBox "Server returned the following error:" + vbCrLf + reply
        End If
End SubPrivate 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
在mail from命令以后有503的错误,提示为 you are not authorized to send to mail as <mail from:<[email protected]>>
  各位高手,请问这是怎么会事啊?是不是需要服务器的认证? 如何取得认证呢?
                     无论晴天也好,雨天也好,我希望和你一起度过~~~~风笛

解决方案 »

  1.   

    使用AUTH Login命令进行身份验证.
      

  2.   

    C:auth login
    S:334 VXNlcm5hbWU6
    C:邮箱账号(Base64)
    S:334 UGFzc3dvcmQ6
    C:密码(Base64)
    S:235 验证成功
      

  3.   

    鱼哥哥,怎么样用base64编码啊?  上边倒是有一个解码的程序。。
                         无论晴天也好,雨天也好,我希望和你一起度过~~~~风笛
      

  4.   

    我在线上等啊,有谁可以教给我怎么样用base64编码吗?
                         无论晴天也好,雨天也好,我希望和你一起度过~~~~风笛
      

  5.   

    我在 smtp.SendData "DATA" + vbCrLf取得肯定验证以后发送下文sfullmsg = "DATE:" & Format$(Now, "dd mmm yy ttttt") & vbCrLf & "form:" & "[email protected]" & vbCrLf & "to:" & "[email protected]" & vbCrLf & "sbuject:" & "test" & vbCrLf & vbCrLf & "this is a test" & vbCrLf & "." & vbCrLf
        smtp.SendData sfullmsg 
    这时,服务器返回 550 your message was blocked.... 请问这是为什么啊?                     无论晴天也好,雨天也好,我希望和你一起度过~~~~风笛