Hi @rasimm ,
I found myself in a similar situation, but it involved tickets and replies.
To send attachments I used Nodejs and the package Axios like described here
To get inline attachments you could also use cheerio to do some sort of web scraping of the description if there is a “img” tag, but I didn’t find a way to get the names of the images if it isn’t defined in the “img” tag, so you’ll have to use a dummy name.
In this example I needed to send the image as base64 string to another application, but you can skip the converstion from arraybuffer to string.
async function getInlineAttachment(description) {
let urls = [];
let inlineAttachmentsList = [];
const $ = cheerio.load(description);
$("div > img").each((i, element) => {
const image = $(element).attr("src");
urls.push(image);
});
for (const url of urls) {
let count = 1;
let res = null;
try {
res = await axios.get(url, { responseType: 'arraybuffer' });
} catch (error) {
console.log(error);
//return error;
}
let content = res.headers['content-type'];
let file = {
data: Buffer.from(res.data, 'binary').toString('base64'),
name: `image${count}.${content.slice(content.indexOf("/") + 1)}`
};
inlineAttachmentsList.push(file);
count++;
}
return inlineAttachmentsList;
}
There are some tutorials (<-this isn’t a link to cheerio stuff, it’s something automatic that this forum does, I didn’t put a link in there) on how to use cheerio for webscraping in the web (even something on youtube).
I hope this helps.