Sub test_cdo_with_image()
strSMTP = "smtp.orange.fr"
sMessage = "<html>salut une image1 <br> <img src=""cid:balloon.bmp""><br>UNE AUTRE IMAGE <br><img src=""cid:balloon2.bmp""></html>"
sImageFile = "F:\sauvegarde\Bateau 2.jpg"
sImageFile2 = "H:\diverse image\Cascade et rivière\YOSEMITE6M.jpg"
SendMail "moimeme@hotmail.fr", "destinataire2@hotmail.fr", "une image", sMessage, sImageFile, sImageFile2, "password", strSMTP
End Sub
' send email using public mail servers
Function SendMail(strFrom, strSendTo, strSubject, strMessage, sImageFile, sImageFile2, strPassword, strSMTP)
Set oEmail = CreateObject("CDO.Message")
'configure message
With oEmail.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
'.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic
'.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUser
'.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
.Update
End With
' build message
With oEmail
.From = strFrom
.To = strSendTo
.Subject = strSubject
.HTMLbody = strMessage
Set objBP = .AddRelatedBodyPart(sImageFile, "balloon.bmp", 1)
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<balloon.bmp>"
objBP.Fields.Update
Set objBP = .AddRelatedBodyPart(sImageFile2, "balloon2.bmp", 1)
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<balloon2.bmp>"
objBP.Fields.Update
End With
' send message
On Error GoTo gestioneerr
oEmail.Send
MsgBox "message envoyé"
Exit Function
gestioneerr:
MsgBox "SendMail Failed:" & Err.Description
End Function