Hi
Use this code:
Option Explicit
Function SendMail(Sender As String, Subject As String, Reciever As String, Text As String, Password As String, AttachFile As String, mailserver As String, portnum As String) As Boolean
If Sender <> "" Or Password <> "" Then
Dim iMsg, iConf, Flds, schema, SendEmailGmail
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = mailserver
Flds.Item(schema & "smtpserverport") = portnum
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = Sender
Flds.Item(schema & "sendpassword") = Password
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
With iMsg
DoEvents
.To = Reciever
.From = Sender
.Subject = Subject
.HTMLBody = Text
.Sender = Sender
.Organization = "S.M.B Productions"
.ReplyTo = Sender
If AttachFile <> "" Then
.AddAttachment (AttachFile)
End If
Set .Configuration = iConf
SendEmailGmail = .send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
SendMail = True
Else
MsgBox "Please, Fill the Sender Mail Address or Sender Mail Password", vbCritical, "Connection Error"
SendMail = False
End If
End Function