Generate new mail or *.msg or *.eml file



  • After I generate a report or file I usually want to send this file including a custom e-mail text (based on a template) and including an image.

    Pretty similar to clicking a <a href="mailto:xxx@xxx.com;subject=kdsjf;body=hugebodywithimages>Send e-mail</a>

    However what I want to do is add a lot of styled text/html in the "body" part and also images and attachements. Would it be possible to either create a template creating this in a good way. Or a template creating a *.msg or *.eml file that can be opened in the local E-mail software and forwarded to the correct receipt?

    I could have had the "e-mail server" send an e-mail but I want that to be different "end users".

    Thank you for the feedback.



  • I'm not sure I understand the question.

    Do you send an email using jsreport custom script?
    Or you call jsreport, get back the report and attach it to the email, but now you would like to generate also the email body?



  • I want to call jsreport and get back a *.eml or *.msg so I can open it in my e-mail software and end the e-mail. So basically using jsreport as an "e-mail templater".



  • I am looking at the eml file example and it is just a text file .
    There are probably many approaches, but one could look like this:

    1. Create a template that renders in the content the email body.
    2. Create a template that renders the email attachment.
    3. Create a script that invokes attachment render and creates the eml file using a third-party library and attach it to the body template.

    The script could look like this. But it is really just from the top of my head without reading the eml lib doc or trying this out. I believe you will be able to finalize this to the desired needs.

    const jsreport = require('jsreport-proxy')
    const emlformat = require('eml-format')
    async function afterRender(req, res) {
      const attachmentRes = await jsreport.render({ template: { name:  'my attachment' } })
    
      const email = { 
          from: '',
          html: res.content.toString(),
          attachments: [{ data: attachmentRes.content }]
      }
      
      const emlBuffer =  await emlformat.build(email)
      res.content = emlBuffer
    }
    


  • Thx!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.