VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8520
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6870
   LinkTopic       =   "Form1"
   ScaleHeight     =   8520
   ScaleWidth      =   6870
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   8
      Left            =   240
      TabIndex        =   9
      Text            =   "c:\test.txt"
      Top             =   4080
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   7
      Left            =   240
      TabIndex        =   8
      Text            =   "mypassword"
      Top             =   3600
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   6
      Left            =   240
      TabIndex        =   7
      Text            =   "me@gmail.com"
      Top             =   3120
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   5
      Left            =   240
      TabIndex        =   6
      Text            =   "465"
      Top             =   2640
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   4
      Left            =   240
      TabIndex        =   5
      Text            =   "smtp.gmail.com"
      Top             =   2160
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   3
      Left            =   240
      TabIndex        =   4
      Text            =   "body text"
      Top             =   1680
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   2
      Left            =   240
      TabIndex        =   3
      Text            =   "other@gmail.com"
      Top             =   1200
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   1
      Left            =   240
      TabIndex        =   2
      Text            =   "test e mail"
      Top             =   720
      Width           =   5775
   End
   Begin VB.TextBox txtInfo 
      Height          =   375
      Index           =   0
      Left            =   240
      TabIndex        =   1
      Text            =   "user@gmail.com"
      Top             =   240
      Width           =   5775
   End
   Begin VB.CommandButton cmdTest 
      Caption         =   "&Test"
      Height          =   495
      Left            =   600
      TabIndex        =   0
      Top             =   7800
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
          sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
          sSmtpUser As String, sSmtpPword As String, _
      sFilePath As String, bSmtpSSL As Boolean) As String
      
          On Error GoTo SendMail_Error:
          Dim lobj_cdomsg As CDO.Message
          Set lobj_cdomsg = New CDO.Message
          lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
          lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
          lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
          lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = 1
          lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
          lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
          lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
          lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = 2
          lobj_cdomsg.Configuration.Fields.Update
          lobj_cdomsg.To = sTo
          lobj_cdomsg.From = sFrom
          lobj_cdomsg.Subject = sSubject
          lobj_cdomsg.TextBody = sBody
          lobj_cdomsg.AddAttachment (sFilePath)
          lobj_cdomsg.Send
          Set lobj_cdomsg = Nothing
          SendMail = "ok"
          Exit Function
          
SendMail_Error:
          SendMail = Err.Description
End Function


Private Sub cmdTest_Click()
    Dim retVal As String
    retVal = SendMail(txtInfo(0), txtInfo(1), txtInfo(2), txtInfo(3), txtInfo(4), txtInfo(5), txtInfo(6), txtInfo(7), txtInfo(8), True)
    Me.Caption = retVal
End Sub

Private Sub txtInfo_GotFocus(Index As Integer)
    txtInfo(Index).SelStart = 0
    txtInfo(Index).SelLength = Len(txtInfo(Index))
End Sub
