Send email to multiple addresses with atachments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DylaneJC
    New Member
    • Nov 2017
    • 5

    Send email to multiple addresses with atachments

    Hi everyone,

    I need a help. I've been in many many forums looking for help but not satisfied.

    Here is my trouble :

    I want to send multiple email to multiple addresses located in my database. My database has an attachment field that I want to send directly to each line of the database.

    Can someone can help me? I use IBM Lotus Notes.

    Here is the code I use, but it doesn't want to take attachment from my database.


    Code:
    'Sending e-mail to manager
    Private Sub Commande219_Click()
    
    'Variable
      Dim rst As DAO.Recordset
      Dim strSQL As String
      Dim strMessageType As String
      Dim strTitre As String
      Dim strMsg As String
      
      
      
      
     
      ' Titre du message
      strTitre = "{Objet} -- Résolu" _
    
      
      ' Message to send
      ' Les signes {...} seront remplacés plus loin par
      ' les infos Client
      strMessageType = "Bonjour," _
        & vbCrLf & vbCrLf _
        & "En date du {Date}, Nous avons reçu du client {Nom_Client} la réclamation en objet." & vbCrLf & vbCrLf _
        & "Nous vous écrivons pour vous informer que cela a été pris en compte et désormais clôt." & vbCrLf _
        & vbCrLf & "Nous vous souhaitons une bonne réception" _
        & vbCrLf & vbCrLf & "~~ Service de Réclamations - UGB ~~"
      
      ' Open the querry
      ' (seuls les gestionnaire ayant un email sont concernés ici)
      strSQL = " SELECT * FROM [Reclamations] WHERE (((Reclamations.Etat)='Clôturée')) "
        
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
      
      ' Browse the client list
      While Not rst.EOF
        ' Construire un message personnalisé
        ' (on remplace chaque {...} du message par les champs
        ' équivalents de la requête
        strMsg = Replace(strMessageType, "{Nom_Client}", rst("Nom_Client"))
        strMsg = Replace(strMsg, "{Date}", rst("Date"))
        strTitre = Replace(strTitre, "{Objet}", rst("Objet"))
        
    
        'Send the e-mail
        SendMail rst("E-mail_gest"), strTitre, strMsg, False
        
        ' Next client
        rst.MoveNext
      Wend
      
      ' One empty ressources
      rst.Close
      Set rst = Nothing
      
      
      CurrentDb.Execute ("UPDATE Reclamations SET Reclamations.Etat = 'Archivée' WHERE (((Reclamations.Etat) = 'Clôturée')) ")
      
      ' A bit message of confirmation
      MsgBox "E-mail de clôture envoyé aux gestionnaires!", vbInformation, "UGB -- Service de Réclamations"
    End Sub
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #2
    Do you not want to leave some clues as to what's going wrong where? I doubt you'll get much interest if you can't even post your own question properly. Our experts will know you expect them to do more work on your problem that you're even prepared to do. We'll see how it goes. You may get very lucky.

    Comment

    • DylaneJC
      New Member
      • Nov 2017
      • 5

      #3
      Hi,

      What I mean is this:

      *I get a database which contains several coloumns (ID, Objet, Email, Attachment, ...)
      *I have an Attachment field, which contains all the attachment inserted from a Form.

      I want to send the same email to all my database addresses, including the attachment located in it.

      This code is the module I use to send message :

      Code:
      '
      Public Sub SendMail(ByVal strEmail As String, _
        ByVal strObj As String, _
        ByVal strMsg As String, _
        ByVal blnEdit As Boolean)
      On Error Resume Next
      DoCmd.SendObject acSendNoObject, , , strEmail, , , strObj, strMsg, blnEdit
      End Sub
      And here is the code to send message :

      Code:
      'Sending e-mail to manager
      Private Sub Commande219_Click()
       
      'Variable
        Dim rst As DAO.Recordset
        Dim strSQL As String
        Dim strMessageType As String
        Dim strTitre As String
        Dim strMsg As String
       
       
       
       
       
        ' Titre du message
        strTitre = "{Objet} -- Résolu" _
       
       
        ' Message to send
        ' Les signes {...} seront remplacés plus loin par
        ' les infos Client
        strMessageType = "Bonjour," _
          & vbCrLf & vbCrLf _
          & "En date du {Date}, Nous avons reçu du client {Nom_Client} la réclamation en objet." & vbCrLf & vbCrLf _
          & "Nous vous écrivons pour vous informer que cela a été pris en compte et désormais clôt." & vbCrLf _
          & vbCrLf & "Nous vous souhaitons une bonne réception" _
          & vbCrLf & vbCrLf & "~~ Service de Réclamations - UGB ~~"
       
        ' Open the querry
        ' (seuls les gestionnaire ayant un email sont concernés ici)
        strSQL = " SELECT * FROM [Reclamations] WHERE (((Reclamations.Etat)='Clôturée')) "
       
        Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
       
        ' Browse the client list
        While Not rst.EOF
          ' Construire un message personnalisé
          ' (on remplace chaque {...} du message par les champs
          ' équivalents de la requête
          strMsg = Replace(strMessageType, "{Nom_Client}", rst("Nom_Client"))
          strMsg = Replace(strMsg, "{Date}", rst("Date"))
          strTitre = Replace(strTitre, "{Objet}", rst("Objet"))
       
       
          'Send the e-mail
          SendMail rst("E-mail_gest"), strTitre, strMsg, False
       
          ' Next client
          rst.MoveNext
        Wend
       
        ' One empty ressources
        rst.Close
        Set rst = Nothing
       
       
        CurrentDb.Execute ("UPDATE Reclamations SET Reclamations.Etat = 'Archivée' WHERE (((Reclamations.Etat) = 'Clôturée')) ")
       
        ' A bit message of confirmation
        MsgBox "E-mail de clôture envoyé aux gestionnaires!", vbInformation, "UGB -- Service de Réclamations"
      End Sub
      The problem I encounter is when I select the attachment field with this code, I get an error telling that the "Data type is not compatible" .

      Hope it's now clear. Thanks

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #4
        I won't pretend that this is something I feel I can help with Dylane, but if someone sees it and wants to help, can you tell us the line number in your recent post where the code stops and you see the message. When the code stops it gives an option to debug which, when selected, shows the code with the line it's on having a yellow background. It may be line #46 but I'm not sure.

        In truth, we mostly recognise when someone struggles to express their problem but doesn't do it very well, compared to when someone is just too lazy to be bothered. Clearly you've tried so experts are likely to see that and try harder for you. Good luck.

        Comment

        • DylaneJC
          New Member
          • Nov 2017
          • 5

          #5
          Hi,

          There is no error while runing that code. I just need to improve it so that I can send the attachments related to each email addresses in my database.

          Also, instead of improving that code, if you get another code which can do the same thing by including the related attachment of each database fields, it'll be Good.



          Thanks

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #6
            Originally posted by DylaneJC
            DylaneJC:
            The problem I encounter is when I select the attachment field with this code, I get an error telling that the "Data type is not compatible".
            How are you getting that error if there is no error?

            I still don't believe I can help you Dylane, but if anyone else sees this and wants to they'll be more inclined to if they have a better understanding of what you're struggling with. Certainly the idea that other code is acceptable rather than the need to fix what you have may make it easier, but they may still be confused by what looks like a contradiction above. I doubt that's what you meant but it still looks that way.

            Alternatively, if you'd like to buy a product that already handles such stuff for you there are many about. One I could vouch for, by an Access MVP friend, but can't here as that would be commercial which isn't allowed in these forums. So, all I can say is there are some out there that will save you a lot of trouble. You could do a search for access emailer and see what comes up. If what you find refers to Access MVP or Luke Chung then you'll have found the one I'm thinking of, but the web's a wonderful thing and you can choose whichever suits you, if you even want to go that way. It's just an idea.

            Good luck.

            Comment

            • DylaneJC
              New Member
              • Nov 2017
              • 5

              #7
              Hi,

              Sorry for beeing late.

              the problem appear when I try this code :

              Code:
              'Sending e-mail to manager
              Private Sub Commande219_Click()
               
              'Variable
                Dim rst As DAO.Recordset
                Dim strSQL As String
                Dim strMessageType As String
                Dim strTitre As String
                Dim strMsg As String
                Dim strAtt As Object
              
               
               
               
               
               
                ' Titre du message
                strTitre = "{Objet} -- Résolu" _
               
               
                ' Message to send
                ' Les signes {...} seront remplacés plus loin par
                ' les infos Client
                strMessageType = "Bonjour," _
                  & vbCrLf & vbCrLf _
                  & "En date du {Date}, Nous avons reçu du client {Nom_Client} la réclamation en objet." & vbCrLf & vbCrLf _
                  & "Nous vous écrivons pour vous informer que cela a été pris en compte et désormais clôt." & vbCrLf _
                  & vbCrLf & "Nous vous souhaitons une bonne réception" _
                  & vbCrLf & vbCrLf & "~~ Service de Réclamations - UGB ~~"
               
                ' Open the querry
                ' (seuls les gestionnaire ayant un email sont concernés ici)
                strSQL = " SELECT * FROM [Reclamations] WHERE (((Reclamations.Etat)='Clôturée')) "
               
                Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
               
                ' Browse the client list
                While Not rst.EOF
                  ' Construire un message personnalisé
                  ' (on remplace chaque {...} du message par les champs
                  ' équivalents de la requête
                  strMsg = Replace(strMessageType, "{Nom_Client}", rst("Nom_Client"))
                  strMsg = Replace(strMsg, "{Date}", rst("Date"))
                  strTitre = Replace(strTitre, "{Objet}", rst("Objet"))
                  strAtt = Replace(strAtt, "{Justificatif}", rst("Justificatif"))
               
               
                  'Send the e-mail
                  SendMail rst("E-mail_gest"), strTitre, strMsg, False
               
                  ' Next client
                  rst.MoveNext
                Wend
               
                ' One empty ressources
                rst.Close
                Set rst = Nothing
               
               
                CurrentDb.Execute ("UPDATE Reclamations SET Reclamations.Etat = 'Archivée' WHERE (((Reclamations.Etat) = 'Clôturée')) ")
               
                ' A bit message of confirmation
                MsgBox "E-mail de clôture envoyé aux gestionnaires!", vbInformation, "UGB -- Service de Réclamations"
              End Sub
              Then the error appears on line 10 and 45.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #8
                Late is fine Dylane. Carrying on a conversation without directing your responses to what's already been said is less so. If you aren't going to respond to my points/questions there's really very little point in my posting them. I expect that may be a language problem but if you don't understand you can always say so. Just moving on without regard to my comments can't possibly work.

                Good luck anyway.

                Comment

                • DylaneJC
                  New Member
                  • Nov 2017
                  • 5

                  #9
                  Hi,

                  Drop all down.

                  Thanks for all

                  Comment

                  Working...