in my node js project, I am using gmail to send mail, mails are going fine, except that when I put data in tabular form with HTML code then rather printing the data in tabular form, it simply prints the html code.
what am I missing here, should I user any specific npm, as of now I am using nodemailer.
You might be writing the HTML code in the text field. Use nodemailer's html field
var mailOptions = {
html: '<b>Hello world!</b>',
}
and write your HTML code into this field.
Related
I am working with Jodit editor on a react project. When I create a note and send to database, and displays the note, it displays fine, but when I try to edit the content and save, the rendered text/content now contains some html tags and this "<p><". I have tried using renderHTML to convert it to only plain text, but that doesn't seem to work. I really need help on converting to plain text alone. The render renderHTML works fine when creating a new note, but doesn't convert to plain text when I try to edit the content.
Before you use the Jodit contents in a non-Jodit environment, you'll need to use a utility that converts the HTML tags.
One library that does this already is html-to-text.
On the backend, the actual code is as simple as
const { conversion } = require('html-to-text');
let adjustedText = conversion('<p>Your string of HTML code here</p>');
... unless you want to feed optional parameters to the conversion() function, like wordwrap. See html-to-text documentation for that.
I want to show html body in mail, I was sending mail through SMTP server using windows service. I write the request in a file & pass this file to MIME.Load() method to read that file and extract the data from that file, but here I get body in plain text format, & so empty body shows when actual email sent. I code for this as below, I use C# for coding
var message = MimeMessage.Load(emailFile);
I have html body but when I checked this message it gives me only plain text and does not shows its html version. I don't understand here how to set or change plain text body to html body in Mime. Does anyone knows about the solution. Thanks
In my current project, we are sending some user chosen services to the mail address provided in input.
We are using a HTML file to format the services and copying this html template to 'mail.Body' before sending the email.
The emails are sent using Sendgrid
When recieving this in gmail ,only for some clients (Set-A) ,even for short email '[Message clipped] View entire message' is shown at the bottom of the email.
We use similar html template to send it for different clients(Set -B), but '[Message clipped] View entire message' is NOT DISPLAYED in this mail ,even when the email is longer.
Tried minified HTML template , but still 'View entire message' is shown at bottom of gmail for only Set-A clients.
The HTML file size before copying to mail body for Set-A (40.11KB) is smaller than that of Set-B (49.09KB).
So I am assuming size is not the problem for this
I compared both the HMTL templates, no difference in styles or other HTML tags. Just the text content is different.
Kindly advise how to avoid this 'View Entire message' option being displayed.
For me it had to do with the character set of the email body. Email body "Hej på dig!" and "Content-Type: text/plain; charset=UTF-8" would reproduce the bug.
You need to make sure that the email body is indeed encoded as declared (check using "show original"). After converting the body from ISO-8859-1 to UTF-8 the problem went away.
I am working upon the project using node.js with express.js framework and view engine set to "ejs". The project's functions is to:
1. Get an input from a user.
2. Using the input send the request to the website's API.
3. Print the certain data from that API (including the ID to be used later).
4. When user clicks on the item (that is an 'a' tag) in the list consisting of the aforementioned data - use the ID of this item to send another request to the same website to get a more detailed info about the item.
I am stuck at the step 4. And the question is: How to send this id from the .ejs file to post request in node.js when the user clicks on the item?
Doing it the other way is simple: response.render("view name", {nodeJsVar: ejsVar}); But how to pass it back?
Thanks for the help!
First of all, you cannot send any data "from the .ejs file" - what you can do is to send it from the browser, that has a rendered HTML (and possibly JavaScript) and not EJS.
You can do it with some client-side JavaScript in which case you can do whatever you want.
You can do it by embedding the variable's value in a URL as a route parameter or a query parameter if you're using standard <a href="..."> links.
You can put a hidden input in a form if you're using forms and buttons.
You can put it in any part of the request if you're using AJAX.
Just to make sure you know what is what because it can be confusing - here X is a path parameter:
http://localhost/something/X
and here X is a query parameter:
http://localhost/something?x=X
try this (assuming you use jQuery):
$.ajax({
url: '/routename_to_handle_id',
type: 'POST',
data: { id: id }
}).done(function(response){
//callback to handle if it's successful
})
I'm using a mix of ejs and emailjs to send out emails in my node.js app when various events happen. I'd like to embed a base64 image (a small logo) into the email when it sends, but both Outlook and Gmail (plus Inbox by Google) fail to render the image.
I'm using this bit of code to find the mime type of the image and put together the base64 string:
MyApp.prototype.ImageToBase64 = function(image) {
var mime = require("mime")
file = fs.readFileSync(__dirname + "/images/" + image, { encoding: 'base64'})
return 'data:' + mime.lookup(image) + ';base64,' + file;
}
That works great, because I'm able to copy and paste that resulting string right into my browser and see the image. But when I send the email via emailjs, Outlook converts the +s to +. When I "View Original" in Gmail, the base64 is split up into 'chunks'. Each chunk is on a newline and each line ends with a =. If I take Gmail's version and remove the = and newline then paste it into my browser, the whole picture loads perfectly, but it just refuses to load anywhere else, regardless of whether the user is in my contact list or not.
Here's the code I'm using to send the email:
// Host, username, password and SSL (false) all set above here
server.send({
text: myTemplate,
from: "me#example.com",
to: "someone#example.com",
subject: "Testing",
attachment: [
{data:myTemplate, alternative:true}
]
})
And the template looks like this (truncated, as the other bits aren't important):
<body>
<p><img src="<%- ImageToBase64("logo.png") %>"></p>
<h1><%= Name %> has been triggered</h1>
<p><%= Name %> has been triggered. It was triggered on <%= TheDate %></p>
Any hints?
EDIT: I tried setting the headers in the "attachment" property, but with no luck
Outlook uses Word to render the images, and Word does not support embedded (src="data:image") images.
You need to attach the image as a file and set the Content-ID MIME header to the value matching the cid attribute on the image (<img src="cid:xyz">) in the HTML body.
Okay, so even though this answer is from 2013, it seems like the wisdom still holds true, in that base64 image support sucks in email clients.
Basically the only mail clients that still support inline images are either older ones (e.g. Office 2007), or Apple / Android's default mail apps.
While that's a bit disappointing, it's not the end of the world, as the email will only be seen by people on the same network as my app, so I can just point to the image hosted on the web portion of the app.
But for anyone else trying this, host your image on an image sharing site like Imgur or on your own server and use a regular ol' <image> tag to display it.
So much for self-contained emails, right?