On Error GoTo erreur
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pwd"
.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
.Update
End With
strbody = "Bonsoir" & vbNewLine & vbNewLine & _
"Merci de ..." & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
With iMsg
Set .Configuration = iConf
.To = "toto@orange.fr"
.CC = ""
.BCC = ""
.From = """titi"" <titi@gmail.com>"
.Subject = "Fichier"
.AddAttachment "c:\temp\toto.txt"
.TextBody = strbody
.Send
End With
Exit Sub
erreur:
MsgBox "Echec d'envoi, merci de joindre le fichier manuellement"
On Error Resume Next
Exit Sub
Application.DisplayAlerts = False
ActiveWorkbook.Close False
ActiveWorkbook.Saved = False
ActiveWindow.Close
End Sub