Posts: 37
Threads: 14
Joined: Aug 2018
Reputation:
0
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
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
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
Posts: 37
Threads: 14
Joined: Aug 2018
Reputation:
0
(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
I've not used html that much, but everytime is a first.
Best regards
Marcus
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
14.11.2019, 08:56
(This post was last modified: 14.11.2019, 08:56 by Erwin van der Zwart.)
Hi,
Here is a sample how to build a HTML formatted energy report.
BR,
Erwin
Posts: 22
Threads: 3
Joined: Aug 2019
Reputation:
0
Hi,
How can I combine the HTML report with a csv attachment?
Gr.
Geert
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
See this thread: https://forum.logicmachine.net/showthread.php?tid=394
3rd argument (message) should contain HTML that you want to send.
Posts: 22
Threads: 3
Joined: Aug 2019
Reputation:
0
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
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
What kind of variables do you want to add?
Posts: 22
Threads: 3
Joined: Aug 2019
Reputation:
0
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
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
Line 48 is incorrect, try this:
Code: res, err = mailattach(MainEmail, Subject, htmldata, Filename, csv, 'text/csv')
Posts: 22
Threads: 3
Joined: Aug 2019
Reputation:
0
Posts: 156
Threads: 40
Joined: Mar 2021
Reputation:
2
05.05.2023, 07:09
(This post was last modified: 05.05.2023, 07:11 by Fahd.)
(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 routinessl3_get_record:wrong version number
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
Change secure = 'sslv23', to secure = 'tlsv1_2',
Posts: 156
Threads: 40
Joined: Mar 2021
Reputation:
2
(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',
}
Posts: 7764
Threads: 42
Joined: Jun 2015
Reputation:
447
For port 587 you need to change secure to starttls instead of tlsv1_2
Posts: 156
Threads: 40
Joined: Mar 2021
Reputation:
2
(05.05.2023, 07:25)admin Wrote: For port 587 you need to change secure to starttls instead of tlsv1_2
Thanks a lot
|