Bonjour à tous,

Je tente d’envoyer des mails à partir d’Excel par une procédure CDO avec le bout de code suivant (récupéré et adapté à partir du forum).

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Public Const Expediteur = "<toto@taf.fr>"
Public Const MAIL_SENDUSING = 2
Public Const MAIL_AUTHENTICATE = 1
Public Const MAIL_CPT_SENDUSR = "Login"
Public Const MAIL_CPT_SENDPASS = "Motdepasse"
Public Const MAIL_SMTP_SERVER = "<serveur smtp>"
Public Const MAIL_SMTP_SERVERPORT = 587
 
Sub CDO_Snd(Destinataire As String, Titre As String, Corps As String)
On Error GoTo Sortie_Erreur
    Dim i As Long
    Dim objEmail As Object
 
    Set objEmail = CreateObject("CDO.Message") 'Crée un objet mail
 
    objEmail.From = Expediteur
    objEmail.To = Destinataire
    objEmail.Subject = Titre
    objEmail.TextBody = Corps
 
    With objEmail.Configuration.Fields
        .Item(CdoConfiguration.cdoSendUsingMethod) = MAIL_SENDUSING
        .Item(CdoConfiguration.cdoSMTPAuthenticate) = MAIL_AUTHENTICATE
        .Item(CdoConfiguration.cdoSendUserName) = MAIL_CPT_SENDUSR
        .Item(CdoConfiguration.cdoSendPassword) = MAIL_CPT_SENDPASS
        .Item(CdoConfiguration.cdoSMTPServer) = MAIL_SMTP_SERVER
        .Item(CdoConfiguration.cdoSMTPServerPort) = MAIL_SMTP_SERVERPORT
        .Update
    End With
    objEmail.Send
Exit Sub
Sortie_Erreur:
    MsgBox Err.Description
End Sub
Toutefois, j’ai systématiquement le message d’erreur « Le transport a échoué dans sa connexion au serveur ».

Je pense que cela peut venir du fait que nous utilisons un serveur Exchange mais je ne sais pas comment contourner ce problème.

En vous remerciant par avance pour l’aide que vous pourrez m’apporter,

Yersin