Пример на вб6.
Код
Public Function SendMail(adresant As String, _
adresat As String, adresantpass As String, mailsubj As String, _
mailbody As String, smtpservak As String, Optional mailattach1 As String)
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = adresant
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = adresantpass
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpservak
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Flds.Update
iMsg.Configuration = iConf
iMsg.To = adresat
iMsg.From = adresant
iMsg.Subject = mailsubj
iMsg.TextBody = mailbody
If mailattach1 <> "" Then
iMsg.AddAttachment = mailattach1
End If
iMsg.Send
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Function