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
| Public Sub EnvoiMailCDO(Chemin As String, envoi_pap As String)
'On Error GoTo err
'DoCmd.Close acForm, "Formulaire1"
Dim mMessage As Object
Dim mConfig As Object
Dim mChps
If Nz(Me.[Adresse de messagerie].Value, "") = "" Then
MsgBox "L'adresse du destinataire est absente." & vbCrLf & "L'envoi est annul?", vbCritical
Exit Sub
End If
If Nz(evaluateur_email, "") = "" Then
MsgBox "L'adresse de l'?metteur est absente." & vbCrLf & "L'envoi est annul?", vbCritical
Exit Sub
End If
Set mConfig = CreateObject("CDO.Configuration")
mConfig.Load -1
Set mChps = mConfig.Fields
'Sheets("EnvoiMail").Select
With mChps
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Adapter suivant votre serveur de mail. (exemple pour Gmail.)=> Hormail "smtp.live.com"
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = evaluateur_smtp
'En principe, 25 fonctionne avec tout les serveurs.
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Vous pouvez essayer sans ces trois lignes
'Mais si votre serveur demande une authentification,
If Me.[Adresse de messagerie].Value <> "" Then
.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "1"
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = evaluateur_email
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = evaluateur_emailpwd
End If
'Si votre serveur demande une connexion s?re (SSL)
' If [E14].Value <> "non" Then
.item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "true"
' End If
.Update
End With
Set mMessage = CreateObject("CDO.Message")
With mMessage
Set .Configuration = mConfig
.To = Me.[Adresse de messagerie].Value
.From = evaluateur_email
If Me.Coche_CopieMail.Value = -1 Then .CC = evaluateur_email
.Subject = Me.mail_objet.Value
.TextBody = Me.mail_contenu.Value & vbCrLf & vbCrLf & Me.mail_signature
'Pour ajouter une pi?ce jointe, un fichier, classeur, image etc.
Select Case envoi_pap
Case "OUI"
'DoCmd.OpenReport "SPAP-04", acViewPreview, , "[ID] = [Forms]![Formulaire1].ID.Value"
DoCmd.OpenReport "SPAP-04", acViewPreview, , "[ID] = " & ID_EN_COURS '[Forms]![Formulaire1].ID.Value"
DoCmd.OutputTo acOutputReport, , "PDF", Chemin & ".pdf"
.AddAttachment Chemin & ".pdf"
Case "NON"
End Select
.Send
End With
DoCmd.Close acReport, "SPAP-04", acSaveNo
MsgBox "Votre message a bien ?t? envoy?" & vbCrLf & "Le plan d'action est ?galement disponible ici : " & vbCrLf & Chemin, vbInformation, "Envoie du mail ? " & Me.[Adresse de messagerie].Value
Me.cmdClose.Enabled = True
' Exit Sub
Set mMessage = Nothing
'Lib?re les ressources
Set mConfig = Nothing
Set mChps = Nothing
'Exit Sub
'err:
'MsgBox err.Number & " - " & err.description, vbCritical
'Me.cmdClose.Enabled = True
End Sub |
Partager