For i = DestStart To DestStart + 3 If OutByte(i) >= 0 And OutByte(i) <= 25 Then OutByte(i) = OutByte(i) + Asc("A") ElseIf OutByte(i) >= 26 And OutByte(i) <= 51 Then OutByte(i) = OutByte(i) - 26 + Asc("a") ElseIf OutByte(i) >= 52 And OutByte(i) <= 61 Then OutByte(i) = OutByte(i) - 52 + Asc("0") ElseIf OutByte(i) = 62 Then OutByte(i) = Asc("+") Else OutByte(i) = Asc("/") End If Next If InByte(ScrStart + 2) = 0 And InByte(ScrStart + 1) = 0 Then OutByte(DestStart + 2) = Asc("=") OutByte(DestStart + 3) = Asc("=") ElseIf InByte(ScrStart + 2) = 0 Then OutByte(DestStart + 3) = Asc("=") End If End Sub
"Helo" 如果成功返回250
"Auth Login" 如果成功返回334
username 如果成功返回334
password 如果成功返回235
"Mail From:" + 发信人 250
"Rcpt To:" + 收信人 250
"Data" & vbcrlf 354
发信件内容 + vbcrlf + "." + vbcrlf 250
"Quit"刚才写错了
Base64Encode就是所谓的Base64编码字符串的函数,InputStr为输入的字符串,OutputStr为输出的字符串Public Sub Base64Encode(ByVal InputStr As String, OutputStr As String)
Dim length As Integer
Dim i As Integer
Dim remain As Integer
length = Len(InputStr)
remain = length Mod 3
If remain <> 0 Then length = length + 3 - remain
ReDim InByte(length) As Byte
ReDim OutByte(length * 4 \ 3) As Byte
CopyMemory InByte(0), ByVal InputStr, length
For i = 0 To length \ 3 - 1
EncodeBytes InByte, OutByte, i * 3, i * 4
Next i
OutputStr = String(length * 4 / 3, Chr(0))
CopyMemory ByVal OutputStr, OutByte(0), length * 4 / 3
End Sub
Public Sub EncodeBytes(InByte() As Byte, OutByte() As Byte, ScrStart As Integer, DestStart As Integer)
Dim tByte As Byte
Dim i As Integer
tByte = InByte(ScrStart) And &HFC
OutByte(DestStart) = tByte / 4
tByte = (InByte(ScrStart) And &H3) * 16 + (InByte(ScrStart + 1) And &HF0) / 16
OutByte(DestStart + 1) = tByte
tByte = (InByte(ScrStart + 1) And &HF) * 4 + (InByte(ScrStart + 2) And &HC0) / 64
OutByte(DestStart + 2) = tByte
tByte = InByte(ScrStart + 2) And &H3F
OutByte(DestStart + 3) = tByte
For i = DestStart To DestStart + 3
If OutByte(i) >= 0 And OutByte(i) <= 25 Then
OutByte(i) = OutByte(i) + Asc("A")
ElseIf OutByte(i) >= 26 And OutByte(i) <= 51 Then
OutByte(i) = OutByte(i) - 26 + Asc("a")
ElseIf OutByte(i) >= 52 And OutByte(i) <= 61 Then
OutByte(i) = OutByte(i) - 52 + Asc("0")
ElseIf OutByte(i) = 62 Then
OutByte(i) = Asc("+")
Else
OutByte(i) = Asc("/")
End If
Next
If InByte(ScrStart + 2) = 0 And InByte(ScrStart + 1) = 0 Then
OutByte(DestStart + 2) = Asc("=")
OutByte(DestStart + 3) = Asc("=")
ElseIf InByte(ScrStart + 2) = 0 Then
OutByte(DestStart + 3) = Asc("=")
End If
End Sub
EncodeBytes是把3个字节变为4个字节的函数.
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
我之前也找到过一些,但由于,unicode和ansi字符串的关系..
总不能得到理想的结果..
多谢龙哥..
接分.