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 110 111 112 113 114 115 116 117
| Public Sub MailLotus(nomFichier As String, nomDestinataire As String, MailDestinataire As String, numeroLigne As Long)
On Error GoTo Gerreur
'Dim session As Domino.NotesSession
Dim Session As Object
Dim db As Object
Dim doc As Object
Dim AttachME As Object
Dim EmbedObj As Object
Dim attachment() As String
Dim mailCopy() As String
Dim i As Integer
Dim fichierJoint As String
Dim txt As String
Dim stream As Object
Dim body As Object
Dim j As Integer
Dim saveNomFichier
Dim mailOK As Boolean
mailOK = InStr(1, MailDestinataire, "@")
If mailOK = False Then
GoTo Gerreur
Else
mailOK = InStr(1, MailDestinataire, ".")
If mailOK = False Then
GoTo Gerreur
End If
End If
'On sauvegarde le nom du fichier pour le réutiliser plus tard ( quand il y a plusieurs destinataires )
saveNomFichier = nomFichier
'On sépare les différentes adresses mail lié à un fournisseur et on le range dans un tableau
If MailDestinataire <> "" Then
mailCopy = Split(MailDestinataire, ";")
End If
For j = 0 To UBound(mailCopy)
nbMail = nbMail + 1
'Texte français
txt = ""
'Texte allemand
'Effacé ici pour confidentialité
'Texte anglais
'Effacé ici pour confidentialité
'Autres lignes
'Effacé ici pour confidentialité
'Signature
'On se connecte à Lotus et on créer le mail
Set Session = CreateObject("notes.notessession")
Set db = Session.GETDATABASE("", "")
Call db.openmail
Session.ConvertMIME = False
Set doc = db.createdocument
With doc
.form = "Memo"
.SendTo = mailCopy(j)
.Subject = "Calendrier de chargement"
' .BodyFormat =
' .HTMLBody =
.From = Session.COMMONUSERNAME
.PostedDate = Now
.SaveMessageOnSend = False
'.BlindCopyTo =
End With
Set stream = Session.CreateStream
Call stream.WriteText(txt)
Set body = doc.CreateMIMEEntity
Call body.SetContentFromText(stream, "text/html;charset=iso-8859-1", ENC_IDENTITY_8BIT)
'On attache ici tous les fichiers dans le mail
If nomFichier <> "" Then
attachment = Split(nomFichier, ";")
For i = 0 To UBound(attachment)
Set AttachME = doc.CREATERICHTEXTITEM("Attachment" & i)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", attachment(i), "Attachment" & i)
doc.CREATERICHTEXTITEM (attachment(i))
Set AttachME = Nothing
Set EmbedObj = Nothing
Next i
End If
doc.PostedDate = Now()
doc.Send 0, mailCopy(j)
nomFichier = saveNomFichier
Set doc = Nothing
Set body = Nothing
Set stream = Nothing
Set Session = Nothing
Next j
Exit Sub
Gerreur:
Sheets("Base de données").Range("C" & numeroLigne).Value = " ERREUR "
MsgBox Err.Number & " : " & Err.Description, vbCritical, "Erreur"
End Sub |
Partager