home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / saver / mimeform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-27  |  19.6 KB  |  579 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form Form1 
  4.    BackColor       =   &H00000000&
  5.    BorderStyle     =   4  'Festes Werkzeugfenster
  6.    Caption         =   "Sends E-Mail with Attachement!"
  7.    ClientHeight    =   5670
  8.    ClientLeft      =   1650
  9.    ClientTop       =   2205
  10.    ClientWidth     =   8190
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   5670
  15.    ScaleWidth      =   8190
  16.    StartUpPosition =   2  'Bildschirmmitte
  17.    Begin VB.CommandButton delattach 
  18.       Caption         =   "Del Attachement"
  19.       Height          =   375
  20.       Left            =   6120
  21.       TabIndex        =   7
  22.       Top             =   600
  23.       Width           =   1695
  24.    End
  25.    Begin VB.ListBox AttachementList 
  26.       Height          =   450
  27.       ItemData        =   "Mimeform.frx":0000
  28.       Left            =   4440
  29.       List            =   "Mimeform.frx":0002
  30.       TabIndex        =   14
  31.       Top             =   120
  32.       Width           =   3375
  33.    End
  34.    Begin VB.CommandButton Exit 
  35.       BackColor       =   &H00000000&
  36.       Height          =   375
  37.       Left            =   4200
  38.       Picture         =   "Mimeform.frx":0004
  39.       Style           =   1  'Grafisch
  40.       TabIndex        =   9
  41.       Top             =   5280
  42.       Width           =   3855
  43.    End
  44.    Begin VB.CommandButton Connect 
  45.       Appearance      =   0  '2D
  46.       BackColor       =   &H00000000&
  47.       Height          =   375
  48.       Left            =   120
  49.       Picture         =   "Mimeform.frx":1E96
  50.       Style           =   1  'Grafisch
  51.       TabIndex        =   8
  52.       Top             =   5280
  53.       Width           =   3975
  54.    End
  55.    Begin MSWinsockLib.Winsock Winsock1 
  56.       Left            =   3360
  57.       Top             =   240
  58.       _ExtentX        =   741
  59.       _ExtentY        =   741
  60.       _Version        =   393216
  61.    End
  62.    Begin VB.ComboBox MailServer 
  63.       Appearance      =   0  '2D
  64.       BackColor       =   &H00FFFFFF&
  65.       Height          =   315
  66.       Left            =   720
  67.       TabIndex        =   1
  68.       Text            =   "mail.kdt.de"
  69.       Top             =   240
  70.       Width           =   2175
  71.    End
  72.    Begin VB.CommandButton Attachement 
  73.       BackColor       =   &H00000000&
  74.       Caption         =   "Add Attachement"
  75.       Height          =   375
  76.       Left            =   4440
  77.       TabIndex        =   6
  78.       Top             =   600
  79.       Width           =   1575
  80.    End
  81.    Begin VB.TextBox Tobox 
  82.       Appearance      =   0  '2D
  83.       BackColor       =   &H00FFFFFF&
  84.       Height          =   285
  85.       Left            =   720
  86.       MaxLength       =   50
  87.       TabIndex        =   2
  88.       Text            =   "galgen@wtal.de"
  89.       Top             =   720
  90.       Width           =   2175
  91.    End
  92.    Begin VB.ComboBox Frombox 
  93.       Appearance      =   0  '2D
  94.       BackColor       =   &H00FFFFFF&
  95.       Height          =   315
  96.       ItemData        =   "Mimeform.frx":3D28
  97.       Left            =   720
  98.       List            =   "Mimeform.frx":3D2A
  99.       TabIndex        =   3
  100.       Text            =   "me@host.com"
  101.       Top             =   1080
  102.       Width           =   2175
  103.    End
  104.    Begin VB.TextBox Subjekt 
  105.       Appearance      =   0  '2D
  106.       BackColor       =   &H00FFFFFF&
  107.       BeginProperty Font 
  108.          Name            =   "Courier"
  109.          Size            =   9.75
  110.          Charset         =   0
  111.          Weight          =   400
  112.          Underline       =   0   'False
  113.          Italic          =   0   'False
  114.          Strikethrough   =   0   'False
  115.       EndProperty
  116.       Height          =   285
  117.       Left            =   720
  118.       MaxLength       =   78
  119.       TabIndex        =   4
  120.       Top             =   1560
  121.       Width           =   7335
  122.    End
  123.    Begin VB.TextBox txtStatus 
  124.       Appearance      =   0  '2D
  125.       BackColor       =   &H00C0C0C0&
  126.       ForeColor       =   &H00000000&
  127.       Height          =   735
  128.       Left            =   120
  129.       MaxLength       =   1000
  130.       MultiLine       =   -1  'True
  131.       ScrollBars      =   2  'Vertikal
  132.       TabIndex        =   0
  133.       TabStop         =   0   'False
  134.       Top             =   3960
  135.       Width           =   7935
  136.    End
  137.    Begin VB.TextBox Mailtxt 
  138.       Appearance      =   0  '2D
  139.       BackColor       =   &H00FFFFFF&
  140.       BeginProperty Font 
  141.          Name            =   "Courier"
  142.          Size            =   9.75
  143.          Charset         =   0
  144.          Weight          =   400
  145.          Underline       =   0   'False
  146.          Italic          =   0   'False
  147.          Strikethrough   =   0   'False
  148.       EndProperty
  149.       Height          =   1965
  150.       Left            =   120
  151.       MultiLine       =   -1  'True
  152.       ScrollBars      =   2  'Vertikal
  153.       TabIndex        =   5
  154.       Top             =   1920
  155.       Width           =   7935
  156.    End
  157.    Begin VB.Label Process 
  158.       BackColor       =   &H00C0C0C0&
  159.       Height          =   255
  160.       Left            =   120
  161.       TabIndex        =   15
  162.       Top             =   4680
  163.       Width           =   7935
  164.    End
  165.    Begin VB.Label ggg 
  166.       Alignment       =   2  'Zentriert
  167.       AutoSize        =   -1  'True
  168.       BackColor       =   &H00000000&
  169.       Caption         =   "Server:"
  170.       ForeColor       =   &H00FFFFFF&
  171.       Height          =   195
  172.       Left            =   105
  173.       TabIndex        =   13
  174.       Top             =   360
  175.       Width           =   525
  176.    End
  177.    Begin VB.Label Label2 
  178.       BackColor       =   &H00000000&
  179.       Caption         =   "To:"
  180.       ForeColor       =   &H00FFFFFF&
  181.       Height          =   255
  182.       Left            =   240
  183.       TabIndex        =   12
  184.       Top             =   840
  185.       Width           =   375
  186.    End
  187.    Begin VB.Label Label3 
  188.       BackColor       =   &H00000000&
  189.       Caption         =   "From:"
  190.       ForeColor       =   &H00FFFFFF&
  191.       Height          =   255
  192.       Left            =   240
  193.       TabIndex        =   11
  194.       Top             =   1200
  195.       Width           =   495
  196.    End
  197.    Begin VB.Label Label4 
  198.       BackColor       =   &H00000000&
  199.       Caption         =   "Subject:"
  200.       ForeColor       =   &H00FFFFFF&
  201.       Height          =   255
  202.       Left            =   120
  203.       TabIndex        =   10
  204.       Top             =   1560
  205.       Width           =   615
  206.    End
  207. Attribute VB_Name = "Form1"
  208. Attribute VB_GlobalNameSpace = False
  209. Attribute VB_Creatable = False
  210. Attribute VB_PredeclaredId = True
  211. Attribute VB_Exposed = False
  212. Dim bTrans As Boolean
  213. Dim m_iStage As Integer
  214. Dim strData As String
  215. Public path As Variant
  216. '*****************************************
  217. 'For the Mime File Field!
  218. '*****************************************
  219. Private Type OPENFILENAME
  220.        lStructSize As Long
  221.        hwndOwner As Long
  222.        hInstance As Long
  223.        lpstrFilter As String
  224.        lpstrCustomFilter As String
  225.        nMaxCustFilter As Long
  226.        nFilterIndex As Long
  227.        lpstrFile As String
  228.        nMaxFile As Long
  229.        lpstrFileTitle As String
  230.        nMaxFileTitle As Long
  231.        lpstrInitialDir As String
  232.        lpstrTitle As String
  233.        flags As Long
  234.        nFileOffset As Integer
  235.        nFileExtension As Integer
  236.        lpstrDefExt As String
  237.        lCustData As Long
  238.        lpfnHook As Long
  239.        lpTemplateName As String
  240. End Type
  241. Const OFN_READONLY = &H1
  242. Const OFN_OVERWRITEPROMPT = &H2
  243. Const OFN_HIDEREADONLY = &H4
  244. Const OFN_NOCHANGEDIR = &H8
  245. Const OFN_SHOWHELP = &H10
  246. Const OFN_ENABLEHOOK = &H20
  247. Const OFN_ENABLETEMPLATE = &H40
  248. Const OFN_ENABLETEMPLATEHANDLE = &H80
  249. Const OFN_NOVALIDATE = &H100
  250. Const OFN_ALLOWMULTISELECT = &H200
  251. Const OFN_EXTENSIONDIFFERENT = &H400
  252. Const OFN_PATHMUSTEXIST = &H800
  253. Const OFN_FILEMUSTEXIST = &H1000
  254. Const OFN_CREATEPROMPT = &H2000
  255. Const OFN_SHAREAWARE = &H4000
  256. Const OFN_NOREADONLYRETURN = &H8000
  257. Const OFN_NOTESTFILECREATE = &H10000
  258. Const OFN_NONETWORKBUTTON = &H20000
  259. Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
  260. Const OFN_EXPLORER = &H80000 ' new look commdlg
  261. Const OFN_NODEREFERENCELINKS = &H100000
  262. Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
  263. Const OFN_SHAREFALLTHROUGH = 2
  264. Const OFN_SHARENOWARN = 1
  265. Const OFN_SHAREWARN = 0
  266. Private Declare Function GetSaveFileName Lib "comdlg32" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
  267. 'Dec's for the X disabling
  268. Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
  269. Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
  270. Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
  271. Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
  272. Const MF_BYPOSITION = &H400&
  273. Const MF_REMOVE = &H1000&
  274. 'For MIME processing
  275. Dim Mime As Boolean
  276. 'For Filehandling
  277. Dim Mimefilename As String
  278. Dim Mimefiles As Integer
  279. Sub DisableX(frm As Form)
  280.      Dim hMenu As Long
  281.      Dim nCount As Long
  282.      hMenu = GetSystemMenu(frm.hwnd, 0)
  283.      nCount = GetMenuItemCount(hMenu)
  284.      'Get rid of the Close menu and its separator
  285.      Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
  286.      Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
  287.      'Make sure the screen updates
  288.      'our change
  289.      DrawMenuBar frm.hwnd
  290. End Sub
  291. '***************************************************************
  292. 'Thanks to Luis Cantero for this Routines
  293. Sub Startrek(frm As Form)
  294. GotoVal = frm.Height / 2
  295. For Gointo = 1 To GotoVal
  296. DoEvents
  297. frm.Height = frm.Height - 100
  298. frm.Top = (Screen.Height - frm.Height) \ 2
  299. If frm.Height <= 500 Then Exit For
  300. Next Gointo
  301. horiz:
  302. frm.Height = 30
  303. GotoVal = frm.Width / 2
  304. For Gointo = 1 To GotoVal
  305. DoEvents
  306. frm.Width = frm.Width - 100
  307. frm.Left = (Screen.Width - frm.Width) \ 2
  308. If frm.Width <= 2000 Then Exit For
  309. Next Gointo
  310. End Sub
  311. Function SaveDialog(Form1 As Form, Filter As String, Title As String, InitDir As String) As String
  312. Dim ofn As OPENFILENAME
  313. Dim A As Long
  314. ofn.lStructSize = Len(ofn)
  315. ofn.hwndOwner = Form1.hwnd
  316. ofn.hInstance = App.hInstance
  317. If Right$(Filter, 1) <> "|" Then Filter = Filter + "|"
  318. For A = 1 To Len(Filter)
  319. If Mid$(Filter, A, 1) = "|" Then Mid$(Filter, A, 1) = Chr$(0)
  320. ofn.lpstrFilter = Filter
  321. ofn.lpstrFile = Space$(254)
  322. ofn.nMaxFile = 255
  323. ofn.lpstrFileTitle = Space$(254)
  324. ofn.nMaxFileTitle = 255
  325. ofn.lpstrInitialDir = InitDir
  326. ofn.lpstrTitle = Title
  327. ofn.flags = OFN_HIDEREADONLY Or OFN_CREATEPROMPT
  328. A = GetSaveFileName(ofn)
  329. If (A) Then
  330. SaveDialog = Left$(Trim$(ofn.lpstrFile), Len(Trim$(ofn.lpstrFile)) - 1)
  331. Mimefilename = Left$(Trim$(ofn.lpstrFileTitle), Len(Trim$(ofn.lpstrFileTitle)) - 1)
  332. SaveDialog = ""
  333. End If
  334. End Function
  335. '***************************************************************
  336. Private Sub Attachement_Click()
  337. Mime = True
  338. Mimefiles = Mimefiles + 1
  339. path = SaveDialog(Me, "*.*", "Attache file as", App.path)
  340. Form1.AttachementList.List(Mimefiles - 1) = path
  341. End Sub
  342. Private Sub delattach_Click()
  343. If Form1.AttachementList.List(AttachementList.ListIndex) <> "" Then
  344. path = ""
  345. Form1.AttachementList.List(AttachementList.ListIndex) = ""
  346. Mimefiles = Mimefiles - 1
  347. End If
  348. End Sub
  349. '***************************************************************
  350. 'Routine for connecting to the server
  351. '***************************************************************
  352. Private Sub Connect_Click()
  353. ' Little Error check
  354. If Tobox.Text = "" Or InStr(Tobox.Text, "@") = 0 Then
  355. MsgBox "To: Is not correct!"
  356. Exit Sub
  357. End If
  358. If Winsock1.State <> sckClosed Then Winsock1.Close
  359. Winsock1.LocalPort = 0
  360. Winsock1.Protocol = sckTCPProtocol
  361. Winsock1.Connect MailServer.Text, "25"
  362. Process.Caption = "Connected to " & MailServer.Text
  363. bTrans = True
  364. m_iStage = 0
  365. Transmit m_iStage
  366. End Sub
  367. Private Sub Exit_Click()
  368. On Error Resume Next
  369. Call Startrek(Me)
  370. If Winsock1.State <> sckClosed Then Winsock1.Close 'Fehler bereinigen durch schlie
  371. End Sub
  372. Private Sub Form_Load()
  373. Call DisableX(Me)
  374. End Sub
  375. '***************************************************************
  376. 'Routine for arraving Data
  377. '***************************************************************
  378. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  379. On Error Resume Next
  380. Winsock1.GetData strData, vbString
  381. txtStatus.Text = txtStatus.Text & strData 'Zeigt Daten in Statusleiste an
  382. If bTrans Then
  383.     m_iStage = m_iStage + 1
  384.     Transmit m_iStage
  385. End If
  386. End Sub
  387. '***************************************************************
  388. 'Sends the E-Mail
  389. '***************************************************************
  390. Private Sub Transmit(iStage As Integer)
  391. Dim Helo As String
  392. Dim pos As Integer
  393. Select Case m_iStage
  394. Case 1:
  395. Helo = Frombox.Text
  396. pos = Len(Helo) - InStr(Helo, "@")
  397. Helo = Right$(Helo, pos)
  398. Winsock1.SendData "HELO " & Helo & vbCrLf
  399. strData = ""
  400. Call WaitForResponse
  401. Case 2:
  402. Winsock1.SendData "MAIL FROM: <" & Trim(Frombox.Text) & ">" & vbCrLf
  403. strData = ""
  404. Call WaitForResponse
  405. Case 3:
  406. Winsock1.SendData "RCPT TO: <" & Trim(Tobox.Text) & ">" & vbCrLf
  407. strData = ""
  408. Call WaitForResponse
  409. Case 4:
  410. Winsock1.SendData "DATA" & vbCrLf
  411. strData = ""
  412. Call WaitForResponse
  413. Case 5:
  414. ' Calls the routine to send the Header
  415. Call SendMimetxt(Frombox.Text, Tobox.Text, Subjekt.Text, Mailtxt.Text, Form1.AttachementList.List(0))
  416. strData = ""
  417. Call WaitForResponse
  418. 'Finish the E-Mail sending process
  419. Case 6:
  420. Winsock1.SendData "QUIT" & vbCrLf
  421. Process.Caption = "E-Mail was sended!"
  422. m_iStage = 0
  423. bTrans = False
  424. strData = ""
  425. Call WaitForResponse
  426. End Select
  427. End Sub
  428. '***************************************************************
  429. 'Routine for Winsock Errors
  430. '***************************************************************
  431. Private Sub Winsock1_Error(ByVal number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  432. MsgBox "Error:" & Description, vbOKOnly, "Winsock Error!"  ' Show error message
  433. If Winsock1.State <> sckClosed Then
  434. Winsock1.Close
  435. Process.Caption = "Disconnected"
  436. End If
  437. End Sub
  438. '***************************************************************
  439. 'Routine for sending a MIME txt
  440. '***************************************************************
  441. Private Sub SendMimetxt(txtFrom, txtTo, txtSubjekt, txtMail, txtMimePath)
  442. Dim temp As Variant
  443. If txtMimePath <> "" Then
  444. 'Prepare the MIME Mail Header
  445. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  446. 'If you want additional Headers like Date,Message-Id,...etc. !
  447. 'simply add them below                                      !
  448. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  449. temp = temp & "From: " & txtFrom & vbNewLine
  450. temp = temp & "To: " & txtTo & vbNewLine
  451. temp = temp & "Subject: " & txtSubjekt & vbNewLine
  452. 'Do not change this Headers
  453. temp = temp & "Mime-Version: 1.0" & vbNewLine
  454. temp = temp & "Content-Type: multipart/mixed; boundary=" + Chr(34) + "NextMimePart" + Chr(34) + vbNewLine
  455. temp = temp & vbNewLine & "This is a multi-part message in MIME format." + vbNewLine
  456. temp = temp & "--NextMimePart" + vbNewLine
  457. 'Header plus Message
  458. temp = temp & vbCrLf & txtMail
  459. 'Send the Mime Header and the Message
  460. Winsock1.SendData temp
  461. 'Call Attachement Routine
  462. SendMimeAttachement (txtMimePath)
  463. 'Send the E-Mail without Attachement
  464. temp = temp & "From: " & txtFrom & vbNewLine
  465. temp = temp & "To: " & txtTo & vbNewLine
  466. temp = temp & "Subject: " & txtSubjekt & vbNewLine
  467. temp = temp & vbCrLf & txtMail
  468. 'Send Data and finish it!
  469. Winsock1.SendData temp
  470. Winsock1.SendData vbCrLf & "." & vbCrLf
  471. End If
  472. End Sub
  473. '**************************************************************
  474. 'NEW! Waits until time out, while waiting for response
  475. '**************************************************************
  476. Sub WaitForResponse()
  477. Dim Start As Long
  478. Dim Tmr As Long
  479. Start = Timer
  480. While Len(strData) = 0
  481.     Tmr = Timer - Start
  482.     DoEvents ' Let System keep checking for incoming response
  483.         
  484.     'Wait 50 seconds for response
  485.     If Tmr > 50 Then
  486.         MsgBox "SMTP service error, timed out while waiting for response", 64, "Error!"
  487.         strData = ""
  488.         If Winsock1.State <> sckClosed Then
  489.         Winsock1.Close
  490.         Process.Caption = "Disconnected"
  491.         End If
  492.         Exit Sub
  493.     End If
  494. End Sub
  495. '***************************************************************
  496. 'Routine for sending a MIME Attachement
  497. '***************************************************************
  498. Private Sub SendMimeAttachement(path As Variant)
  499. 'Dim Global
  500. Dim l As Long, i As Long, FileIn As Long
  501. Dim temp As Variant
  502. 'For Encoding BASE64
  503. Dim b As Integer
  504. Dim Base64Tab As Variant
  505. Dim bin(3) As Byte
  506. Dim s As Variant
  507. 'Base64Tab holds the encode tab
  508. Base64Tab = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/")
  509. 'Gets the next free filenumber
  510. FileIn = FreeFile
  511. 'Open Base64 Input File
  512. Open path For Binary As FileIn
  513. 'Preparing the Mime Header
  514. temp = vbCrLf + "--NextMimePart" + vbNewLine
  515. temp = temp + "Content-Type: application/octet-stream; name=" + Chr(34) + Form2.txtSave.Text + Chr(34) + vbNewLine
  516. temp = temp + "Content-Transfer-Encoding: base64" + vbNewLine
  517. temp = temp + "Content-Disposition: attachment; filename=" + Chr(34) + Form2.txtSave.Text + Chr(34) + vbNewLine
  518. Winsock1.SendData temp & vbCrLf
  519. l = LOF(FileIn) - (LOF(FileIn) Mod 3)
  520. For i = 1 To l Step 3
  521. 'Read three bytes
  522. Get FileIn, , bin(0)
  523. Get FileIn, , bin(1)
  524. Get FileIn, , bin(2)
  525. 'Always wait until there're more then 64 characters
  526. If Len(s) > 64 Then
  527.     Do
  528.     Loop Until Winsock1.State = 7
  529.     Process.Caption = "Send Attachement..." & i & " Bytes from " & l
  530.     DoEvents
  531.     s = s + vbCrLf
  532.     Winsock1.SendData s
  533.     s = ""
  534. End If
  535. 'Calc Base64-encoded char
  536.     b = (bin(0) \ 4) And &H3F 'right shift 2 bits (&H3F=111111b)
  537.     'the character s holds the encoded chars
  538.     s = s + Base64Tab(b)
  539.     b = ((bin(0) And &H3) * 16) Or ((bin(1) \ 16) And &HF)
  540.     s = s + Base64Tab(b)
  541.     b = ((bin(1) And &HF) * 4) Or ((bin(2) \ 64) And &H3)
  542.     s = s + Base64Tab(b)
  543.     b = bin(2) And &H3F
  544.     s = s + Base64Tab(b)
  545.  Next i
  546. 'Now, you need to check if there is something left
  547. If Not (LOF(FileIn) Mod 3 = 0) Then
  548. 'Reads the number of bytes left
  549. For i = 1 To (LOF(FileIn) Mod 3)
  550.     Get FileIn, , bin(i - 1)
  551. Next i
  552. 'If there are only 2 chars left
  553. If (LOF(FileIn) Mod 3) = 2 Then
  554.     b = (bin(0) \ 4) And &H3F 'right shift 2 bits (&H3F=111111b)
  555.     s = s + Base64Tab(b)
  556.     b = ((bin(0) And &H3) * 16) Or ((bin(1) \ 16) And &HF)
  557.     s = s + Base64Tab(b)
  558.     b = ((bin(1) And &HF) * 4) Or ((bin(2) \ 64) And &H3)
  559.     s = s + Base64Tab(b)
  560.     s = s + "="
  561. 'If there is only one char left
  562.     b = (bin(0) \ 4) And &H3F 'right shift 2 bits (&H3F=111111b)
  563.     s = s + Base64Tab(b)
  564.     b = ((bin(1) And &H3) * 16) Or ((bin(1) \ 16) And &HF)
  565.     s = s + Base64Tab(b)
  566.     s = s + "=="
  567. End If
  568. End If
  569. 'Send the characters left
  570. If s <> "" Then
  571.     s = s & vbCrLf
  572.     Winsock1.SendData s
  573. End If
  574. 'Send the last part of the MIME Body
  575. Winsock1.SendData vbCrLf & "--NextMimePart--" & vbCrLf
  576. Winsock1.SendData vbCrLf & "." & vbCrLf
  577. Close FileIn
  578. End Sub
  579.