Macro pour envoyer des mails sous Lotus Notes

Bonjour,
Je cherche à construire une macro capable d'envoyer un mail (je changerai le corps du message à chaque envoi) avec, éventuellement, un fichier excel en PJ.

Quelqu'un pourrait-il m'aider svp ?

merci !
Configuration: Windows 2000
Internet Explorer 6.0

5 réponses

  • Votes
  • Date
  • Date décroissante
  1. Merci,

    ca fonctionne,
    encore qq modif pour l'ajuster à mes besoins mais c'est parfait
    1. J'ai oublié de (re)préciser que je souhaite que les mails soient envoyés sous Lotus Notes ...
      1. Salut j'ai développé une macro sous excel pour mes besoins elle fonctionne pour ouvrir des incidents auprès de notre centre d'incident.

        Pour utiliser il faut :
        - Créer un module dans excel et faire un copier coller du code ci dessous
        - Créer un bouton auquel on associe l'appel à la fonction sendnotesmail avec en paramétre les données de la fonction, j'ai pris des nom signifiant pour simplifier.
        - Attention : recipient est une table (a vous de voir combien de destinataires maxi vous voulez (moi j'en ai mis deux)
        - Responsable est pour moi le demandeur (la personne qui est en copie on peut mettre une table aussi mais il faut mettre variant à la place de string. j'ai préparé les destinataires cachés mais sans les utiliser.
        Les commentaires sont en anglais, car pour moi c'est plus facile (question d'habitude) ayant toujours programmé en anglais.

        Si ce code vous a été utile merci de me la faire savoir, ça me fera plaisir. ;-)

        Bye !

        Sub SendNotesMail(subject As String, Attachment As String, recipient As Variant, bodytext As String, SaveIt As Boolean, responsable As String)
        '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)
        Dim test1 As String
        Dim test2 As Integer
        Dim Len_Att As Double
        Dim Str_Att, St_Len As Double
        Dim Nbr_Att As Integer
        Dim Att_Pos, St_Str, St_Pos As Integer
        Dim X_Attachement$
        Dim X_Attach, Str_SendTo As String

        '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
        'test1 = Sheets("demande").Cells(1, 3)
        'test2 = InStr(3, Sheets("demande").Cells(1, 3), " ")
        MailDbName = " "
        '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
        If Attachment <> " " Then
        Set AttachME = MailDoc.CREATERICHTEXTITEM(Attachment)
        Set EmbedObj = AttachME.embedobject(1454, "", Attachment, "ATT")
        MailDoc.CREATERICHTEXTITEM ("ATT")
        End If

        MailDoc.Form = "Memo"
        MailDoc.sendto = recipient
        'MailDoc.CopyTo = responsable
        'MailDoc.BlindCopyTo = bccRecipient
        'sendto(0) = first
        'sendto(1) = second
        ' maildoc.sendto = sendto
        If responsable <> " " Then
        MailDoc.Copyto = responsable
        End If
        MailDoc.subject = subject
        MailDoc.body = bodytext
        MailDoc.SAVEMESSAGEONSEND = SaveIt
        'Set up the embedded object and attachment and attach it
        'read the attachment string and generate a number of attachment equal to the selected attachment
        'must be separated by a chr$(10)
        'in case of other separator change the instr$ command
        '
        ' Set AttachME = MailDoc.CREATELINKHOTSPOTITEM("file:\\chaumapps\partage$")
        ' Set EmbedObj = AttachME.embedobject(AttachME)

        '
        '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
      2. @dragon75Merci beaucoup, j'ai hâte de la tester !!
        en revanche, mon anglais est plutôt moyen... vous serait -il possible de traduire, svp ?

        d'avance merci

        ++
      3. @dragon75Ca marche. C'est très bien. Merci beaucoup.
    2. que signifie "(subject As String, Attachment As String, recipient As Variant, bodytext As String, SaveIt As Boolean, responsable As String)" au début ?
      sont-ce les variables à déclarer ?
      1. pour ma part j'ai mis toutes ces variables en les déclarant une a unes

        au lieu de
        (subject As String, Attachment As String, recipient As Variant, bodytext As String, SaveIt As Boolean, responsable As String)

        j'ai

        ()
        dim subject as string
        dim attachment as ..
        ....

        et ensuite

        recipient = xxx@xxx.fr