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 40
| Sub EnvoiMail(strTo As String, strFrom As String, strSubject As String, strBody As String, Optional strCc As String, Optional strCci As String, Optional PJ As Variant)
Dim iMsg As Object, iConf As Object, Flds As Object
Dim i As Integer
Set iMsg = CreateObject("cdo.message")
Set iConf = CreateObject("cdo.configuration")
Set Flds = iConf.fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'remplacez "smtp.nomserveur.fr" par le nom de serveur de votre FAI :
'http://outlook.developpez.com/faq/index.php?page=Configuration#Paras_FAI
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.piou.com"
.Update
End With
With iMsg
Set .Configuration = iConf
.To = strTo
.Cc = strCc
.Bcc = strCci
.From = strFrom
.Subject = strSubject
.HTMLBody = strBody
For i = 0 To UBound(PJ)
.AddAttachment (PJ(i))
Next i
.Send
End With
End Sub
Sub LaunchPiou()
Dim strBody As String
strBody = "Bonjour<br>" & _
"Ceci est un test d'envoi de mail via le code VBA de PiouPiou.<br><br>" & _
"PIOUPI\o/"
Call EnvoiMail("piou@piou.com", "frompiou@piou.com", "Test envoi mail", strBody, , , "")
End Sub |
Partager