应该如何插入发送附件代码

解决方案 »

  1.   

    .SendData "begin 600 " & sAttachFileName & vbCrLf
          EncodeAndSendFile sAttachArray(iAttach), UU_ENCODE
         .SendData "end" & vbCrLfPrivate Sub EncodeAndSendFile(ByVal strFile As String, Encode As ENCODE_METHOD)'******************************************************************************
    '
    ' Synopsis:     Send a file attachment via an open socket
    '
    ' Parameters:   strFile  - The input file name
    '               Encode   -  type of encoding to use; MIME or UU
    '
    ' Return:       nothing
    '
    ' Description:
    '   Open the file & read characters in. Send the characters through the appropriate
    '   encoder, either MIME (Base64) or UUEncode, before tranmission via an open socket.
    '
    '******************************************************************************Dim hFile               As Integer      ' file handle
    Dim sValue              As String       ' temp string buffer
    Dim bInFile()           As Byte         ' byte array file buffer
    Dim lEventCtr           As Long         ' counter
    Dim lChunkSize          As Long         ' number of bytes to get
    Dim lNumBytes           As Long         ' file pointerIf bInEXE Then On Local Error GoTo File_ErrorhFile = FreeFile
    Open strFile For Binary Access Read As #hFile
    lNumBytes = LOF(hFile)If Encode = MIME_ENCODE Then    Do While lNumBytes
            ' set input buffer size, MUST be a multiple of 57
            lChunkSize = IIf(lNumBytes > 2850, 2850, lNumBytes)
            
            ' read & Base 64 encode a group of characters
            bInFile = InputB(lChunkSize, #hFile)
            frmSocket.sckMail.SendData EncodeBase64Byte(bInFile)
            
            ' adjust file pointer
            lNumBytes = lNumBytes - lChunkSize
            
            DoEvents
        LoopElseIf Encode = UU_ENCODE Then    Do While Not EOF(hFile)
            ' read & UU encode a line of characters
            sValue = Input(45, #hFile)
            frmSocket.sckMail.SendData UUEncodeString(sValue) & vbCrLf
        
            ' DoEvents (occasionally)
            lEventCtr = lEventCtr + 1
            If lEventCtr Mod 50 = 0 Then DoEvents
        LoopEnd IfFile_Done:Close #hFileExit SubFile_Error:    AddError Err.Description
        SendFail
        pbExitImmediately = True
        Resume File_DoneEnd SubPrivate 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 FunctionPrivate Function UUEncodeString(str2UUEncode As String) As String
    '******************************************************************************
    '
    ' Synopsis:     UUEncode a string
    '
    ' Parameters:   str2UUEncode  - The input string
    '
    ' Return:       encoded string
    '
    ' Description:
    '   UU Encode a string. 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 the
    '   UUEncode string array to derive the correct character. The string will be a multiple
    '   of 4 bytes in lenght after conversion, padded with '=' as required. The line length
    '   will be encoded as a leading character (same 0 to 63 encoding) in the return string.
    '
    '******************************************************************************Dim sValue              As String
    Dim lPtr                As Long
    Dim lCtr                As Long
    Dim lLen                As Long
    Dim lLineLen            As Long
    Dim sEncoded            As String
    Dim Bits8(1 To 3)       As Byte
    Dim Bits6(1 To 4)       As BytelLineLen = Len(str2UUEncode)
    ' lines are limited to 63
    If lLineLen > 63 Then Exit FunctionFor lCtr = 1 To Len(str2UUEncode) Step 3
        
         ' Get 3 characters
        sValue = Mid$(str2UUEncode, lCtr, 3)
        lLen = Len(sValue)
        
        ' Move string data into a byte array, then
        ' swap bits to create 4, 6 bit values (0-63)
        If lLen < 3 Then Erase Bits8
        CopyMemory Bits8(1), sValue, lLen
        Bits6(1) = (Bits8(1) And &HFC) \ &H4
        Bits6(2) = (Bits8(1) And &H3) * &H10 + (Bits8(2) And &HF0) \ &H10
        Bits6(3) = (Bits8(2) And &HF) * &H4 + (Bits8(3) And &HC0) \ &H40
        Bits6(4) = Bits8(3) And &H3F    ' Encode new 4 byte string by selecting a character from
        ' the array. Length is determined by 'lLen' to make sure
        ' the file attachment is the right length
        For lPtr = 1 To lLen + 1
            sEncoded = sEncoded & psUUEncodeChr(Bits6(lPtr))
        NextNext' add the line length character
    sEncoded = psUUEncodeChr(lLineLen) & sEncoded' The decoder expects the size to be a multiple of 4 bytes.
    ' Possible sizes for the last packet are: 2, 3 & 4.
    Select Case lLen + 1
        Case 2: sEncoded = sEncoded & "=="      ' send two pad characters
        Case 3: sEncoded = sEncoded & "="       ' send one pad character
        Case 4:                                 ' no pad characers needed
    End SelectUUEncodeString = sEncodedEnd Function
      

  2.   

    TO:fling_boy(andy--天意) ,是不是少了pbBase64Byt这个函数?