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
|
Public Function send_email()
Dim Rst_Mail As dao.Recordset
Dim Emetteur As String
Dim Serveur As String
Dim Port As Integer
Dim MDP As String
Dim Fichier As String
Dim strHtml As String 'variable contenu du corps de message
' Ouvre la ligne des caractéristiques du mailling dans la table "T_RECAPITULATIF"
Set Rst_Mail = CurrentDb.OpenRecordset("select * from T_RECAPITULATIF where Num_Jour = " & ChoixJour & " order by Num_Panier")
' récupère le serveur d'émission dans la table paramètres
Serveur = DLookup("SMTP", "Parametres", Variable = SMTP)
' récupère le port smtp dans la table paramètres
Port = DLookup("Port", "Parametres", Variable = Port)
' récupère le nom de l'émetteur dans la table paramètres
Emetteur = DLookup("Emetteur", "Parametres", Variable = Emetteur)
' récupère le mot de passe dans la table paramètres
MDP = DLookup("MDP", "Parametres", Variable = MDP)
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method = 2 basic = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Serveur
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = Port
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 300
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = Emetteur
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = MDP
.Update
End With
' build email parts
strHtml = "<HTML><HEAD><BODY><p>" & Bjr & "</p>"
strHtml = strHtml & "<p>" & TxtBody1 & "</p>"
strHtml = strHtml & "<br>" & TxtBody2 & "</br>"
strHtml = strHtml & "<br>" & TxtBody3 & "</br>"
strHtml = strHtml & "<br></br>" & Politesse & "<br></br><br></br>"
strHtml = strHtml & "<p align='center'>" & Signature_1 & "</p></body><HTML>"
strHtml = strHtml & "<p align='center'>" & Signature_2 & "</p></body><HTML>"
strHtml = strHtml & "<p align='center'>" & Signature_3 & "</p></body><HTML>"
strHtml = strHtml & "</BODY></HEAD></HTML>"
If Not (Rst_Mail.EOF And Rst_Mail.BOF) Then
Do Until Rst_Mail.EOF = True
On Error Resume Next
Fichier = Application.CurrentProject.Path & "\Récapitulatif panier N° " & Rst_Mail("Num_Panier") & " - " & Rst_Mail("NOM") & " " & Rst_Mail("PRENOM") & ".pdf"
DoCmd.OpenReport "E_RECAPITULATIF", acViewReport, , "[Num_Panier]= " & Rst_Mail("Num_Panier")
DoCmd.OutputTo acOutputReport, "", acFormatPDF, Fichier
DoCmd.Close acReport, "E_RECAPITULATIF"
DoEvents
With cdomsg
.To = Rst_Mail("MAIL")
.FROM = Emetteur
.Subject = "Recapitulatif panier N° " & Rst_Mail("Num_Panier") & " - " & Rst_Mail("NOM") & " " & Rst_Mail("PRENOM")
.HTMLBody = strHtml
.Attachments.DeleteAll
.AddAttachment Fichier
.Send
End With
Kill Fichier
Rst_Mail.MoveNext
Loop
Set cdomsg = Nothing
End If
End Function |
Partager