Private Sub Command1_Click()
Dim Mailto As String 'Mail To
Dim mail As Object ' CDO.MESSAGE
Dim config As Object ' CDO.Configuration
Mailto = InputBox("Enter Mail", "Enter Email Address")
If Mailto <> "" Then ' if it not empty
MsgBox ("Mail will sent to " & Mailto & " Press OK and wait for confirmation message "), "Sending ..."
Else
MsgBox "Canceled , or No Mail entered ", vbCritical, "Error"
'Terminate if the cancel or empty value is found button is clicked!
End If
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
config.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
config.Fields(cdoSMTPServer).Value = "xxxx"
config.Fields(cdoSMTPServerPort).Value = 465
config.Fields(cdoSMTPUseSSL).Value = "true"
config.Fields(cdoSMTPAuthenticate).Value = cdoBasic
config.Fields(cdoSendUserName).Value = "xxxxx"
config.Fields(cdoSendPassword).Value = "xxxxx"
config.Fields.Update
Set mail.Configuration = config
With mail
.To = Mailto
.From = "xxxx"
.Subject = "Test Sub"
.TextBody = "Test Body."
.AddAttachment "c:\users\data.bin"
.Send
End With
Set config = Nothing
Set mail = Nothing
If Err.Number = 0 Then
MsgBox "Message Sent Successfully", vbInformation, "Sent"
End Sub