Is there a way to retrieve only the HTML portion of the message body? The msg:get_data() method returns the entire message body, but I’m specifically interested in obtaining just the HTML content.
Hey there @kindhearted-deer , thanks for posting. To ensure the fastest resolution to your issue, please review the following and follow all the steps:
Mike
(Mike Hillyer)
January 10, 2024, 1:52pm
3
There is not currently an HTML only method.
tom
(Tom Mairs)
January 10, 2024, 4:12pm
4
This was answered in this question about tracking links:
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.
tom
(Tom Mairs)
January 10, 2024, 4:14pm
5
I thought I had filed an enhancement for this as well - looking for it now
tom
(Tom Mairs)
January 10, 2024, 4:51pm
6
Apparently we only discussed it internally, but I have now added it as an enhancement request.
opened 04:48PM - 10 Jan 24 UTC
closed 01:23PM - 09 Sep 25 UTC
enhancement
**The problem**: There are times when you need to modify a message before delive… ry, and at this time, it is doable but cumbersome. For instance, adding an open image link to the HTML part is currently a bit of a chore. It would be helpful to modify a message body to get the MIME parts as variables in the same way you can get a table of headers. Ideally, you can also modify the MIME part and reassemble the message before delivery, but that may be a separate enhancement ticket.
**The current situation**: Take the above suggested open tracking image, for instance. At this time, you need to capture the entire message in a variable, modify it, and reinject it. EG:
```lua
local msg_body = msg:get_data()
-- update body here
-- define and add tracking link to HTML part
local my_tracking_link = '<img src="http://10.0.0.1/img_tracker.jpg" alt="open tracking pixel">'
msg_body = msg_body:gsub("</body>", my_tracking_link .. " </body>")
local msg_payload = kumo.json_encode {
envelope_sender = msg:sender().email,
content = msg_body,
recipients = {
{ email = msg:recipient().email },
},
}
```
The above is a straightforward example and is error-prone.
**Suggested enhancement**: If there were a function to get the message parts into a table that could be modified, it would simplify the process and reduce errors. Something like `msg:get_mime_parts()` might result in a table of all the MIME parts that could then be manipulated, like:
```lua
{"text":"there is nothing here","html":"<body><p>There is HTML here</p></body>"}
```
Now I can modify or entirely replace a MIME part without accidentally changing others.
**Other Considerations**: The opposite (set_) is valid in that assembling a message should be the reverse. Something like this would be handy:
```lua
msg:set_mime_parts("text":"there is nothing here","html":"<body><p>There is _new_ HTML here</p></body>")
```
The reality is that it will probably only be built if someone thinks it is important enough to pay for the work.