This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LM and PDF?
#1
Hi

I've tried to search for this, but can't find anything.

Is it possible to somehow create a template with scripting that can import values from LM database and visualize it with graphs and all the imported values and send it to mail as an PDF without third party services?

The case is, im creating a energy monitoring system.
My initial tought was to just send a pre fabricated CSV file to the owner, but started to think it might be better to create a PDF document which was sent to the owner every month with graphs and values for each office area or industrial building which makes it easier to bill their different tenants.

Best regards
Marcus
Reply
#2
Hi,

Why not build a html page and add it to the mail? This way you can make a great layout with any format you like and add it to the body of the mail.

I have some energy report samples with tables so it shows how to do that but you need to optimize them..

BR,

Erwin
Reply
#3
(13.11.2019, 15:50)Erwin van der Zwart Wrote: Hi,

Why not build a html page and add it to the mail? This way you can make a great layout with any format you like and add it to the body of the mail.

I have some energy report samples with tables so it shows how to do that but you need to optimize them..

BR,

Erwin

Great!

If you could share it with me, I would be very greatfull Big Grin  

I've not used html that much, but everytime is a first.

Best regards
Marcus
Reply
#4
Hi,

Here is a sample how to build a HTML formatted energy report.
.lua   HTML Energy Report.lua (Size: 4.81 KB / Downloads: 122)


BR,

Erwin
Reply
#5
Hi,

How can I combine the HTML report with a csv attachment?
Gr.
Geert
Reply
#6
See this thread: https://forum.logicmachine.net/showthread.php?tid=394
3rd argument (message) should contain HTML that you want to send.
Reply
#7
Hi Admin,

It's not quite clear for me how I can implement HTML text with variable text into the Message


Code:
    -- adjustable information

AantalECG = 189                                              -- Aantal armaturen                             
MainEmail = 'example@example.be'                              -- mailadres voor main email
Subject = '72.01 resultaat functietest_'  ..os.date('%F , %X')            -- Onderwerp email
Message = '72.01 resultaat functietest op '  ..os.date('%F , %X')        -- Bericht in email
Filename = os.date("%y%m%d")..'_72.01_functietest.csv'                -- Naam voor csv-bestand
FINummer = 72.01                                                                                                        -- FI nummer van het gebouw

   -- get current data as table
now = os.date('*t')
   
current_hourandseconds = string.format("%02d", now.hour)  .. ":" .. string.format("%02d", now.min)
current_date = string.format("%02d", now.day) .. "-" .. string.format("%02d", now.month) .. "-" .. now.year



-- HTML text to implement in Message

htmldata = [[<html style="font-family:Arial">
<body>

  <h1>]] ..FINummer.. [[ Attest functietest </h1>

<p>Beste,</p>
  <p>Hierbij bevestigen wij u dat op ]] .. current_date .. [[ om ]] .. current_hourandseconds .. [[ uur een functietest van de veiligheidsverlichting voor het gebouw met FI-nummer ]] ..FINummer.. [[ werd uitgevoerd.</p>
  <p>De resultaten van deze functietest zijn opgenomen als bijlage: ]] ..Filename.. [[ van een mail verzonden vanaf example@example.be.</p>
 
  <table style="width:100%">
    <tr>
        <td><b>Aantal armaturen</b></td>
        <td><b>Resultaat</b></td>
    </tr>
    <tr>
  <td>]] .. AantalECG.. [[</td>
    <td>]] ..FINummer.. [[</td>
    </tr>
</table>


<p>Wanneer u vragen heeft over het testrapport kunt u contact opnemen met example@example.be.</p>
<p>Dit rapport is verzonden op ]] .. current_date .. [[ om ]] .. current_hourandseconds .. [[ uur.</p>
</body>
</html>]]

-- Sending main email

  res, err = mailattach(MainEmail, Subject, Message , Filename, csv, 'text/csv')
  log(res, err,'main email sent') 

    script.disable(_SCRIPTNAME) 
    end
Gr.
Geert
Reply
#8
What kind of variables do you want to add?
Reply
#9
Hi,

The variables I want to add  are implemented in the HTML text as shown in the testscript:

]] ..FINummer.. [[
]] ..current_date.. [[
]] ..current_hourandseconds.. [[
]] ..Filename.. [[
]] ..AantalECG.. [[

For every project variables are put on top ( --adjustable information--) to change depending the project.

Now the message in my mail is as shown at the top, but I want to replace it by the HTML text (--HTML text to implement in Message--)
Gr.
Geert
Reply
#10
Line 48 is incorrect, try this:
Code:
res, err = mailattach(MainEmail, Subject, htmldata, Filename, csv, 'text/csv')
Reply
#11
Thx again!
Gr.
Geert
Reply
#12
(14.11.2019, 08:56)Erwin van der Zwart Wrote: Hi,

Here is a sample how to build a HTML formatted energy report.


BR,

Erwin

Hi, 

While I'm trying to use the script from Erwin van der Zwart I got this error in the logs, 
Quote:* string: error:1408F10B:SSL routinesConfusedsl3_get_record:wrong version number
Reply
#13
Change secure = 'sslv23', to secure = 'tlsv1_2',
Reply
#14
(05.05.2023, 07:14)admin Wrote: Change secure = 'sslv23', to secure = 'tlsv1_2',
Forget to mention that I changed this part 
    headers = {
   
    from = "sed <xxx>",
    to = "Rcpt Name <xxx>",
    subject = "Report"
  },

    body = {
        [1] = {
            headers = { ['Content-type'] = 'text/html' },
      body = htmldata
    },
    }
}
r, e = smtp.send{
    rcpt = "<xxx>" ,
    from = '<xxx>',
    source = ltn12.source.chain(source, filter),
    user = 'xxx',
    password = 'xxx',
    server = 'smtp.office365.com',
    port = 587,
    secure = 'tlsv1_2',
}
Reply
#15
For port 587 you need to change secure to starttls instead of tlsv1_2
Reply
#16
(05.05.2023, 07:25)admin Wrote: For port 587 you need to change secure to starttls instead of tlsv1_2

Thanks a lot  Big Grin
Reply


Forum Jump: