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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
'---------------------------------------------------------------------------------------
' Procedure : SendMailCDO
' Author : Oliv'
' Date : 24/04/2008
' Purpose :
'---------------------------------------------------------------------------------------
'
Function SendMailCDO(Sender As String, Receiver As String, _
subject As String, BodyText As String, _
Optional BodyHTML As String, _
Optional Cc As String, _
Optional Bcc As String, _
Optional pvarAttachFile As Variant)
' Microsoft CDO for Windows 2000 Library
Dim Cdo_Message As New CDO.Message
Set Cdo_Message.Configuration = GetSMTPServerConfig()
With Cdo_Message
.To = Receiver
.From = Sender
.subject = subject
.Cc = Cc
.Bcc = Bcc
'.DSNOptions = 2 ' Delivery Status Notification
'pour indiquer le Corps du Mail en brut.
.TextBody = BodyText
'Décommenter pour indiquer le Corps du Mail en HTML.
'.HTMLBody = BodyHTML
'Pour envoyer une page WEB en tant que corps du Mail.
'.CreateMHTMLBody _
"http://groups.google.com/group/microsoft.public.fr.outlook", _
CDO.CdoMHTMLFlags.cdoSuppressNone , "", ""
'ou se trouvant sur son pc
'.CreateMHTMLBody "file:\\C:\INFORMAT\exemples\événements.htm"
' Ajout de la pièce jointe, 1 ou plusieurs fichiers
If Not IsMissing(pvarAttachFile) Then
If IsArray(pvarAttachFile) Then
' parcourrir le tableau
For i = LBound(pvarAttachFile) To UBound(pvarAttachFile)
objEmail.AddAttachment pvarAttachFile(i)
Next i
Else
objEmail.AddAttachment pFileAttach
End If
End If
' If Attach1 <> "" Then
' If Len(Dir(Attach1)) > 0 Then
' .AddAttachment (Attach1)
' Else: MsgBox Attach1 & vbCr & "Ce fichier sera ignoré", _
' , "Fichier à Attacher introuvable !"
' End If
' End If
'Cette commande envoi le Mail
On Error Resume Next
DoEvents
.Send
If Err <> 0 Then
Debug.Print Err.Number & Err.Description & Err.LastDllError
Err.Clear
End If
End With
Set Cdo_Message = Nothing
End Function
Function GetSMTPServerConfig() As Object
' Microsoft CDO for Windows 2000 Library
Dim Cdo_Config As New CDO.Configuration
Dim Cdo_Fields As Object
Set Cdo_Fields = Cdo_Config.Fields
With Cdo_Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.free.fr"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
'.Item(cdoSMTPAuthenticate) = cdoBasic
' IMPORTANT: Storing user names and passwords inside source code
' can lead to security vulnerabilities in your software. Do not
' store user names and passwords in your production code.
'.Item(cdoSendUserName) = "username"
'.Item(cdoSendPassword) = "password"
'.Item (cdoSMTPUseSSL) = False 'Use SSL for the connection (True or False)
'.Item(cdoURLProxyServer) = "server:80"
'.Item(cdoURLProxyBypass) = "<local>"
'.Item(cdoURLGetLatestVersion) = True
.Update
End With
Set GetSMTPServerConfig = Cdo_Config
Set Cdo_Config = Nothing
Set Cdo_Fields = Nothing
End Function |
Partager