Vb 怎样实现smtp身份验证发信  (附上核心代码)高手不吝赐教,感激不尽!!!
Winsock1.SendData GenerateMessageID(Mid(MAIL_FROM, InStr(1, MAIL_FROM, "@") + 1, Len(MAIL_FROM))) & Chr$(13) & Chr$(10)
    Winsock1.SendData "DATE: " & Format(Now, "h:mm:ss") & Chr$(13) & Chr$(10)
    Winsock1.SendData "FROM: " & FROM & " <" & MAIL_FROM & ">" & Chr$(13) & Chr$(10)
                                         
   Winsock1.SendData sBase64Enc("jh8792123") & vbCrLfm_State = MAIL_USER    (这里是我自己看别人的帖子填上去的,但是提示函数未定义。)
         
          
   Winsock1.SendData sBase64Enc("5333773083") & vbCrLfm_State = MAIL_PASS(这里是我自己看别人的帖子填上去的,但是提示函数未定义。)
    Winsock1.SendData "TO: " & MAIL_TO & " <" & RCPT_TO & ">" & Chr$(13) & Chr$(10)
    Winsock1.SendData "Reply-to: " & " <" & REPLY_TO & ">" & Chr$(13) & Chr$(10)
    Winsock1.SendData "SUBJECT: " & SUBJECT & Chr$(13) & Chr$(10)
    Winsock1.SendData "MIME-Version: 1.0" & Chr$(13) & Chr$(10)
    Winsock1.SendData "Content-Type: text/plain; charset=us-ascii" & Chr$(13) & Chr$(10)
    Winsock1.SendData Chr$(13) & Chr$(10)
    
    Winsock1.SendData DATA & Chr$(13) & Chr$(10)
    Log DATA
    Winsock1.SendData Chr$(13) & Chr$(10) & "." & Chr$(13) & Chr$(10)
    
    Log Chr$(13) & Chr$(10) & "."

解决方案 »

  1.   

    你需要去找个生成Base64编码的函数(sBase64Enc)
      

  2.   

    Private Function EncodeBase64Byte(InArray() As Byte) As Byte()'******************************************************************************
    '
    ' Synopsis:     Base 64 encode a byte array
    '
    ' Parameters:   InArray  - The input byte array
    '
    ' Return:       encoded byte array
    '
    ' Description:
    '   Convert a byte array to a Base 64 encoded byte array. Coerce 3 bytes into 4 by
    '   converting 3, 8 bit bytes into 4, 6 bit values. Each 6 bit value (0 to 63) is
    '   then used as a pointer into a base64 byte array to derive a character. This
    '   rountine performs the same task as the EncodeBase64String function that follows it
    '   except that the input and return data types are byte arrays. This is an important
    '   distinction, as this routine is compatible with double byte character sets (DBCS)
    '   like Chinese while the EncodeBase64String function is not.
    '
    '******************************************************************************Dim lInPtr              As Long         ' pointer into input array
    Dim lOutPtr             As Long         ' pointer into output array
    Dim OutArray()          As Byte         ' output byte array buffer
    Dim lLen                As Long         ' number of extra bytes past 3 byte boundry
    Dim iNewLine            As Long         ' line counter' if size of input array is not a multiple of 3,
    ' increase it to the next multiple of 3
    lLen = (UBound(InArray) - LBound(InArray) + 1) Mod 3
    If lLen Then
        lLen = 3 - lLen
        ReDim Preserve InArray(UBound(InArray) + lLen)
    End If' create an output buffer
    ReDim OutArray(UBound(InArray) * 2 + 100)' step through the input array, 3 bytes at a time
    For lInPtr = 0 To UBound(InArray) Step 3
        
        ' add CrLf as required
        If iNewLine = 19 Then
            OutArray(lOutPtr) = 13
            OutArray(lOutPtr + 1) = 10
            lOutPtr = lOutPtr + 2
            iNewLine = 0
        End If
        
        ' convert 3 bytes into 4 base 64 encoded bytes
        OutArray(lOutPtr) = pbBase64Byt((InArray(lInPtr) And &HFC) \ 4)
        OutArray(lOutPtr + 1) = pbBase64Byt((InArray(lInPtr) And &H3) * &H10 + (InArray(lInPtr + 1) And &HF0) \ &H10)
        OutArray(lOutPtr + 2) = pbBase64Byt((InArray(lInPtr + 1) And &HF) * 4 + (InArray(lInPtr + 2) And &HC0) \ &H40)
        OutArray(lOutPtr + 3) = pbBase64Byt(InArray(lInPtr + 2) And &H3F)
        
        ' update pointers
        lOutPtr = lOutPtr + 4
        iNewLine = iNewLine + 1
    Next' add terminator '=' as required
    Select Case lLen
        Case 1: OutArray(lOutPtr - 1) = 61
        Case 2: OutArray(lOutPtr - 1) = 61: OutArray(lOutPtr - 2) = 61
    End Select' add CrLf if not already there
    If OutArray(lOutPtr - 2) <> 13 Then
        OutArray(lOutPtr) = 13
        OutArray(lOutPtr + 1) = 10
        lOutPtr = lOutPtr + 2
    End If' resize output buffer and return
    ReDim Preserve OutArray(lOutPtr - 1)
    EncodeBase64Byte = OutArrayEnd Function