Enoyer un mail sous Excel via Lotus Notes
Bonjour,
Je suis novice en VBA.
J'ai trouvé le code plus bas (qui fonctionne) sur les forums mais je voudrais que le mail s'affiche dans lotus note avant l'envoi afin que l'utilisateur puisse modifier le contenu du mail si besoin.
Que dois-je modifier dans le code?
Merci d'avance.
Code:
Sub SendNotesMail()
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
‘Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.Sendto = "la tu mets l'adresse mail de ton correspondant" '(laisse les "")
MailDoc.CopyTo = "l'adresse de la personne en copie" '(laisse les "")
MailDoc.Subject = "la tu mets le sujet" '(avec des "")
' Construction du corps du message
Set objNotesField = MailDoc.CreateRichTextItem("Body")
With objNotesField
.AppendText "Bonjour,"
.AddNewLine 2
.AppendText "Ci-joint la situation." 'tu peux réjouter des lignes
.AddNewLine 2
.AppendText "Cordialement"
.AddNewLine 1
.AppendText "Martin DUPONT"
.AddNewLine 3
End With
MailDoc.SaveMessageOnSend = True
'Set up the embedded object and attachment and attach it
Attachment1 = "la tu mets le chemin d'acces complet de ton fichier excel.xls"
Attachment2 = "idem 2e fichier"
Attachment3 = "idem 3e ficher"
If Attachment1 <> "" And Attachment2 <> "" And Attachment3 <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment1")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment1, "Attachment1")
MailDoc.CREATERICHTEXTITEM (Attachment1)
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment2")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment2, "Attachment2")
MailDoc.CREATERICHTEXTITEM (Attachment2)
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment3")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment3, "Attachment3")
MailDoc.CREATERICHTEXTITEM (Attachment3)
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Bonsoir,
Si Frédéric SIGONNEAU me lit :
Cela fait une quinzaine d'années que je ne me sers plus de ce code, je ne peux donc pas vous dire s'il fonctionne dans votre version actuelle.
Il vous faut simplement rentrer vos paramètres.
Option Explicit
Sub EnvoyerUnMailNotes(ObjetDuMail As String, MessageDuMail As String, AdresseMail As String)
' Par un auteur inconnu du MPFE - Sans doute Frédéric SIGONNEAU
Dim ObjNotesSession As Object
Dim ObjNotesMailFile As Object
Dim ObjNotesDocument As Object
Dim ObjNotesField As Object
Dim SendMail As Boolean
Dim Msg As String
Dim EMailCCTo As String
Dim EMailBCCTo As String
On Error GoTo SendMailError
EMailCCTo = "" '' Optional
EMailBCCTo = "" '' Optional
Set ObjNotesSession = CreateObject("Notes.NotesSession") ' Etablissement de la connection à Notes
Set ObjNotesMailFile = ObjNotesSession.GETDATABASE("", "") ' Establish Connection to Mail File '' .GETDATABASE("SERVER", "FILE")
ObjNotesMailFile.OPENMAIL 'Ouverture du Mail
Set ObjNotesDocument = ObjNotesMailFile.CREATEDOCUMENT ' Création d'un nouveau mémo
Set ObjNotesField = ObjNotesDocument.APPENDITEMVALUE("Subject", ObjetDuMail) ' Create 'Subject Field'
Set ObjNotesField = ObjNotesDocument.APPENDITEMVALUE("SendTo", AdresseMail) ' Create 'Send To' Field
Set ObjNotesField = ObjNotesDocument.APPENDITEMVALUE("CopyTo", EMailCCTo) ' Adresser en copie
Set ObjNotesField = ObjNotesDocument.APPENDITEMVALUE("BlindCopyTo", EMailBCCTo) ' Adresser en copie cachée
Set ObjNotesField = ObjNotesDocument.CREATERICHTEXTITEM("Body") ' Corps du message
ObjNotesField.APPENDTEXT MessageDuMail
ObjNotesField = ObjNotesField.EMBEDOBJECT(1454, "", ActiveWorkbook.FullName) ' Attacher le fichier --1454 indique un attachement de fichier
ObjNotesDocument.SEND (0) ' Envoi du mail
''Release storage
Set ObjNotesSession = Nothing
Set ObjNotesMailFile = Nothing
Set ObjNotesDocument = Nothing
Set ObjNotesField = Nothing
''Set return code
SendMail = True
Exit Sub
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 SubBonjour Eric,
Merci de votre réponse, je teste votre code aujourd’hui et reviens vers vous.
Je serai bien en peine de vous aider, je n'ai plus accès à un serveur domino.