Menu

#150 envoi par mail

V1.11
closed
nobody
None
2024-12-28
2024-04-23
Anonymous
No

Ticket type : Evolution

Description : Pour mon association, j'aimerais pouvoir envoyer ,par mail , des listes à certains des mes adhérents.

System information : Windows 64 bits / Windows 10 Enterprise LTSC 2021

Discussion

  • Neuts-jl

    Neuts-jl - 2024-04-23

    Pour envoyer un email il faut faire un script LUA
    exemple

    -- Définir le lien mailto
    local mailtoLink = "mailto:destinataire@example.com?subject=Sujet%20de%20l'email&body=Corps%20de%20l'email"
    -- Ouvrir le lien dans le client de messagerie par défaut
    os.execute('start "" "' .. mailtoLink .. '"')
    

    ou si vous en serveur smtp à disposition, utiliser :

    nsbase.internet.sendMail(.....)
    
     

    Last edit: Neuts-jl 2024-04-23
  • Neuts-jl

    Neuts-jl - 2024-04-25

    Exemple complet fonctionnant avec FREE.FR
    Il faudra changer l'UTILISATEUR, MOTDEPASSE , QUI_ENVOI, QUI_RECOIT et la TABLE_OU_REQUETE a envoyer

    function datasetToHtml(datasource)
      local dataset = nsbase.datasetCreate("SQLQuery")
      dataset.SQL=nsbase.application.getSQLFromDatasource(datasource)
      dataset.open()
      local html = '<table border="1">\n'
      local fields = dataset.getfieldnames("table")
    
      html = html .. '<tr>'
      for _, field in pairs(fields) do
        html = html .. '<td><b>' .. field .. '</b></td>'
      end
      html = html .. '</tr>\n'
    
      while not dataset.eof do
        html = html .. '<tr>'
        for _, field in pairs(fields) do
          html = html .. '<td>' .. dataset.getfieldname(field) .. '</td>'
        end
        html = html .. '</tr>\n'
        dataset.next()
      end
      html = html .. '</table>\n'
      dataset.close()
      return html
    end
    
    function sendDatasetToEmail(host, user, password, from, to, subject, datasource)
      local message=string.gsub(datasetToHtml(datasource), '"', '\\"')
    
      nsbase.internet.sendMail('from="' .. from.. '" to='.. to .. ' ' ..
      'subject="'.. subject .. '" message="' .. message .. '" ' ..
      'user=' .. user..' password=' .. password .. ' ' ..
      'host=' .. host ..' ssl=true tls=true contenttype=html ' )
    end
    
    function test:Button1ActionOnClick()
      sendDatasetToEmail('smtp.free.fr:465','UTILISATEUR', 'MOTDEPASSE',
        'QUI_ENVOI <QUI_ENVOI@free.fr>', 'QUI_RECOIT',
        'Liste de personnes', 'TABLE_OU_REQUETE')
      end
    
     

    Last edit: Neuts-jl 2024-04-25
  • Anonymous

    Anonymous - 2024-04-25

    Merci pour l'exemple fourni, je viens de tester, c'est OK.

     
  • Neuts-jl

    Neuts-jl - 2024-04-26

    Ce code est inclu maintenant dans la librairie internet.lua
    https://sourceforge.net/projects/nsbase/files/nsbase-lua-libs/internet.lua/download
    Ca sera maintenant

    internet.sendDatasetToEmail(....)
    
     

    Last edit: Neuts-jl 2024-04-26
  • Neuts-jl

    Neuts-jl - 2024-12-28
    • status: --> closed
    • Group: --> V1.11
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB