Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Function SendMail()
'mpep, auteur inconnu
On Error GoTo SendMailError
' Plage d'adresses e-mail dans une feuille de calcul
For Each Cell In Range("Adresses")
' Cas avec la plage
EMailSendTo = Cell.Value ' Required - Send to address
' Cas avec une seule adresse
'EMailSendTo = "erenaud@normandnet.fr" ' Required - Send to address
EMailCCTo = "" '' Optional
EMailBCCTo = "" '' Optional
Emailsubject = "Envoi d'un document joint" ' Optional
''Establish Connection to Notes
Set objNotesSession = CreateObject("Notes.NotesSession")
''Establish Connection to Mail File
'' .GETDATABASE("SERVER", "FILE")
Set objNotesMailFile = objNotesSession.GETDATABASE("", "")
''Open Mail
objNotesMailFile.OPENMAIL
''Create New Memo
Set objNotesDocument = objNotesMailFile.CREATEDOCUMENT
''Create 'subject Field'
Set objNotesField = objNotesDocument.APPENDITEMVALUE("subject", Emailsubject)
''Create 'Send To' Field
Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", EMailSendTo)
''Create 'Copy To' Field
Set objNotesField = _
objNotesDocument.APPENDITEMVALUE("CopyTo", EMailCCTo)
''Create 'Blind Copy To' Field
Set objNotesField = _
objNotesDocument.APPENDITEMVALUE("BlindCopyTo", EMailBCCTo)
''Create 'Body' of memo
Set objNotesField = objNotesDocument.CREATERICHTEXTITEM("Body")
With objNotesField
.APPENDTEXT "Cet e-mail a été généré par un processus automatique."
.ADDNEWLINE 1
.APPENDTEXT "This e-mail is generated by an automated process."
'.APPENDTEXT "Please follow established contact " & _
"procedures should you have any questions."
.ADDNEWLINE 2
.APPENDTEXT "Cordialement"
.ADDNEWLINE 1
.APPENDTEXT "Eric RENAUD"
End With
''Attach the file --1454 indicate a file attachment
objNotesField = _
objNotesField.EMBEDOBJECT(1454, "", ActiveWorkbook.FullName)
''Send the e-mail
objNotesDocument.SEND (0)
Next Cell
''Release storage
Set objNotesSession = Nothing
Set bjNotesSession = Nothing
Set objNotesMailFile = Nothing
Set objNotesDocument = Nothing
Set objNotesField = Nothing
''Set return code
SendMail = True
Exit Function
SendMailError:
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
SendMail = False
End Function