Search code examples
htmlgmailgoogle-cloud-functions

html content in gmail from firebase cloud functuion


const nodemailer = require('nodemailer');


I send email using firebase functioun and the mail is showing html code but i need to display html content not html code
how to do this? i resive mail as

<!DOCTYPE html><html><head><style>table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%;}td, th { border: 1px solid #dddddd; text-align: left; padding: 8px;}tr:nth-child(even) { background-color: #dddddd;}</style></head><body><h2>HTML Table</h2><table> <tr> <th>Title</th> <th>Price</th> <th>Image</th> </tr> <tr>  <td>Aashirvaad Cumin Powder Pouch</td><td>6</td> <td><img src="https://cdn.shopify.com/s/files/1/2113/0893/products/Aashirvaad_Cumin_Powder_Pouch.png?v=1508267918"  height="102" width="102" alt="Girl in a jacket"></td></tr> <tr>  <td>Aashirvaad Chilli Powder Pouch</td><td>3</td> <td><img src="https://cdn.shopify.com/s/files/1/2113/0893/products/Aashirvaad_Chilli_Powder_Pouch.png?v=1508268124"  height="102" width="102" alt="Girl in a jacket"></td></tr> <tr>  <td>Aashirvaad Coriander Powder Pouch</td><td>1</td> <td><img src="https://cdn.shopify.com/s/files/1/2113/0893/products/Aashirvaad_Coriander_Powder_Pouch.png?v=1508268599"  height="102" width="102" alt="Girl in a jacket"></td></tr></table></body></html>

this and what i need is display as html


Solution

  • When you are sending email to the user, you have two option sending

    1. Sending Simple Text
    2. Sending HTML Content

    Sending Simple Text To send the simple text you need to send email data like this.

    i.e :

    var mailData = {
        from: '[email protected]',
        to: '[email protected]',
        subject: 'Message title',
        text: '<h1>This is not HTML Header</h1>',
    };
    

    Sending HTML Content In order to send HTML Content to the mail, you need to say about that.

    i.e. :

    var mailData = {
        from: '[email protected]',
        to: '[email protected]',
        subject: 'Message title',
        html: '<h1>This is HTML Header</h1>'
    };