'Base64Encode(originalString$)
Public Function Base64Encode(originalString$) deciml = Asc(Left$(originalString$, 1)) For k = 7 To 0 Step -1 If (2 ^ k) <= deciml Then binaryStr$ = binaryStr$ & "1" deciml = deciml - (2 ^ k) Else binaryStr$ = binaryStr$ & "0" End If Next If Len(originalString$) < 3 Then Goto unfpassone deciml = Asc(Mid$(originalString$, 2, 1)) For k = 7 To 0 Step -1 If (2 ^ k) <= deciml Then binaryStr$ = binaryStr$ & "1" deciml = deciml - (2 ^ k) Else binaryStr$ = binaryStr$ & "0" End If Next If Len(originalString$) < 3 Then Goto unfpassone deciml = Asc(Right$(originalString$, 1)) For k = 7 To 0 Step -1 If (2 ^ k) <= deciml Then binaryStr$ = binaryStr$ & "1" deciml = deciml - (2 ^ k) Else binaryStr$ = binaryStr$ & "0" End If Next unfpassone: For k = 1 To 19 Step 6 Select Case Val(Mid$(binaryStr$, k, 6)) Case 0 temp$ = temp$ & "A" Case 1 temp$ = temp$ & "B" Case 10 temp$ = temp$ & "C" Case 11 temp$ = temp$ & "D" Case 100 temp$ = temp$ & "E" Case 101 temp$ = temp$ & "F" Case 110 temp$ = temp$ & "G" Case 111 temp$ = temp$ & "H" Case 1000 temp$ = temp$ & "I" Case 1001 temp$ = temp$ & "J" Case 1010 temp$ = temp$ & "K" Case 1011 temp$ = temp$ & "L" Case 1100 temp$ = temp$ & "M" Case 1101 temp$ = temp$ & "N" Case 1110 temp$ = temp$ & "O" Case 1111 temp$ = temp$ & "P" Case 10000 temp$ = temp$ & "Q" Case 10001 temp$ = temp$ & "R" Case 10010 temp$ = temp$ & "S" Case 10011 temp$ = temp$ & "T" Case 10100 temp$ = temp$ & "U" Case 10101 temp$ = temp$ & "V" Case 10110 temp$ = temp$ & "W" Case 10111 temp$ = temp$ & "X" Case 11000 temp$ = temp$ & "Y" Case 11001 temp$ = temp$ & "Z" Case 11010 temp$ = temp$ & "a" Case 11011 temp$ = temp$ & "b" Case 11100 temp$ = temp$ & "c" Case 11101 temp$ = temp$ & "d" Case 11110 temp$ = temp$ & "e" Case 11111 temp$ = temp$ & "f" Case 100000 temp$ = temp$ & "g" Case 100001 temp$ = temp$ & "h" Case 100010 temp$ = temp$ & "i" Case 100011 temp$ = temp$ & "j" Case 100100 temp$ = temp$ & "k" Case 100101 temp$ = temp$ & "l" Case 100110 temp$ = temp$ & "m" Case 100111 temp$ = temp$ & "n" Case 101000 temp$ = temp$ & "o" Case 101001 temp$ = temp$ & "p" Case 101010 temp$ = temp$ & "q" Case 101011 temp$ = temp$ & "r" Case 101100 temp$ = temp$ & "s" Case 101101 temp$ = temp$ & "t" Case 101110 temp$ = temp$ & "u" Case 101111 temp$ = temp$ & "v" Case 110000 temp$ = temp$ & "w" Case 110001 temp$ = temp$ & "x" Case 110010 temp$ = temp$ & "y" Case 110011 temp$ = temp$ & "z" Case 110100 temp$ = temp$ & "0" Case 110101 temp$ = temp$ & "1" Case 110110 temp$ = temp$ & "2" Case 110111 temp$ = temp$ & "3" Case 111000 temp$ = temp$ & "4" Case 111001 temp$ = temp$ & "5" Case 111010 temp$ = temp$ & "6" Case 111011 temp$ = temp$ & "7" Case 111100 temp$ = temp$ & "8" Case 111101 temp$ = temp$ & "9" Case 111110 temp$ = temp$ & "+" Case 111111 temp$ = temp$ & "/" End Select Next Base64Encode = temp$ End Function Private Sub Command1_Click() Command1.Enabled = False If Text5.Text <> "" Then Base64EncodeFile Text5.Text, RichTextBox1, Text1 End If ConnectToServer "dudley.majordomos.com", Winsock1 End Sub Private Sub Winsock1_Connect() mailSend Text2.Text, Text3.Text, Text4.Text, Text6, Winsock1, Text5.Text, Text1 Command1.Enabled = True End Sub return = Base64Encode("the") return would be: dGjl Notes: You can only pass 3 letters as the arguement. In order to process a whole file for delivery use the function Base64EncodeFile() also included in this bas file For a sample project written in vb6, you can download it from:http://www.dellete.com/sendmail.zip If you like this code and all Let me know at standby@dellete.com by the way If you use this please credit me or something...i KNOW how wanted this code is...and i just spent all day reading rfc's and coding to Get this done...just a small mention would be appreciated... Usage: 'Base64EncodeFile(fileToEncode, tempRTBControl, outputTo) 'Base64EncodeFile "c:\temp\test.zip", richtextb copy the api part up above to a module this is a sample project For this bas file. - first one (1) a winsock control and name it whatever you want - add one (1) richtextbox control and set it's visible option to False - add one (1) textbox With visible set to False and multiline set to True - add four (4) regular textbox' all set visible True * note: you can name them whatever, just remember the following settings For them: one will be the from field, one will be the to field, one will be the subject field and the last one will be the attachment field (you Type the full path in to the file, up to you to create the file open dialog boxes For this...) - add one (1) textbox set to visible = True and multiline = true i suggest making the scrollbars be horizontal. this box is intended For the actual message of the mail - add one (1) button which is the send button in the Click Event of your button add the following line: If Text5.Text <> "" Then Base64EncodeFile Text5.Text, RichTextBox1, Text1 End If ConnectToServer "dudley.majordomos.com", Winsock1 * note: text5.text in this example was the textbox used to Get the FULL path to the file to attach, richtextbox1 is self explanatory and text1.text was the box we set multiline and invisible * note: this is just an example server and the name of the winsock control can be whatever you named it in the Connect Event of your winsock control add this mailSend text2.text, text3.text, text4.text, Text6, Winsock1, Text5.Text, Text1 * note: here is an explanation of the params text2.text was the FROM field (who is sending it) text3.text was the TO field (who it is going to) text4.text was the SUBJECT field (duh) text6.text was the big textbox For the BODY winsock1 is the name of the winsock control text5.text is the filename of the attachment text1 is the name of the hidden textbox control you can leave the last two params off since those are optional and only needed If you want to attach a file last suggestion... when you click the button disable it and Then reenable it after the mailSend procedure: |