1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| On Error GoTo ErrorHandler
Dim oMsg As Object
Dim oConf As Object
Dim vFields As Variant
Set oMsg = CreateObject("CDO.Message")
Set oConf = CreateObject("CDO.Configuration")
'oConf.Load -1 ' CDO Source defaults
Set vFields = oConf.Fields
With vFields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = txtUserLogin.Text
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = txtUserPassword.Text
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 5
.Update
End With
With oMsg
Set .Configuration = oConf
.To = txtDestEmail.Text
.CC = ""
.BCC = ""
' .From = txtSenderAddress.Text
.From = txtUserLogin.Text
.Subject = txtSubject.Text
.TextBody = txtBody.Text
.Send
End With
Exit Sub
ErrorHandler:
MsgBox Str(Err) + vbCrLf + Error$, vbOKOnly + vbCritical, "Sendmail Error" |
Partager