I am trying to send a link in email using mailgun but the anchor tag in html sent as plain text
mg.messages().send({
from: 'mohamed.salah678mo#gmail.com',
to: email,
subject: `${req.currentUser.courseId} results are published by ${req.currentUser.userName}`,
html: `<html>
<body>
<a href='localhost:5000/api/course-results'>results</a>
</body>
</html>
`
}, (error,body) =>{console.log(body.message)})
this returns the word result as a plain text not a clickable link
Related
I am sending emails using the Gmail NodeJS API using these code snippet (leaving auth out of it)
const headers: any = {
'To': event.to,
'Subject': event.subject,
"Content-Type": "text/html; charset='UTF-8'",
"Content-Transfer-Encoding": "base64"
}
let email = ''
for (let header in headers) {
email += header += ": " + headers[header] + "\r\n";
}
email += "\r\n" + event.body;
const theMessage = {
'userId': "me",
'resource': {
'raw': _btoa(unescape(encodeURIComponent(email))).replace(/\+/g, '-').replace(/\//g, '_')
}
}
const auth = new google.auth.OAuth2(
webAppClientId, this.clientSecret, "https://docs-n-data......");
const gmail = google.gmail({version: 'v1', auth})
gmail.users.messages.send(theMessage)
The email renders correctly on most email clients, except the ios email client on iphone. It looks like "chinese" in that client. Please see the attached image, following the suggestion by #DalmTo:
Some articles on the web hint that this might be due to the email being interpreted as UTF-16 instead of UTF-8, but none of them explain what to do.
I am trying to state that the encoding is UTF-8 in the above code, so am not sure whats wrong. Please help, thanks!
Update Maybe the content of the email body is important. The content comes from this template:
const emailBody = `<html>
<body>
<p>Hi {{Customer.First name}},</p>
<p>Your booking is confirmed for {{Date}} at {{Time}} and we have charged you the
amount of £{{Paid}}</p>
<p>Your booking reference is {{Booking number}}.</p>
<p>Use this link to cancel your booking, should you wish to.</p>
<p>Use this link to amend your booking, should you wish to.</p>
</body>
</html>`
Update 2 I changed the template for the email to:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>Hi {{Customer.First name}},</p>
<p>Your booking with The Smart Wash Ltd is confirmed for {{Date}} at {{Time}} and we have charged you the
amount of £{{Paid}}</p>
<p>Your booking reference is {{Booking number}}.</p>
</body>
</html>
And now I get this rendering on iphone mail client. On the ipad mail client and gmail, it renders correctly:
When I view the same email in gmail, and "Show original", I see this:
Not sure who or what is putting the text/plain version in there, but including this detail in case it helps.
I setted "Content-Transfer-Encoding": "8bit" and it worked for me!
I am unable to send click able link via email . Here is my code
const data = {
from: "me#samples.mailgun.org",
to: email,
subject: "password reset",
html: `
<h1>Hey ,we received you have to reset your account password ,${currentDate} </h1>
<h1> Please click on the link to reset your password </h1>\
<a href=${process.env.CLIENT_URL}/resetpassword/${token}> click here </a>
` ,
};
Mail is successfully sent to the email but the link is not clickable
It looks like
I guess you have to add " for href property:
click here
Every time a user is registered to my website, I would like to send an automatic email to him with
the logo of the company, this is how I did it but for some reason, the IMG doesn't show.
mailSender.sendEmail('donotreplay#example.co.il','example#mail.com', " Hey "
+userToCreate.ownerName+" , Welcome to Example",
`
<table>
<tr style="background:black"> <img src="img/logo.png"></tr>
<tr>Check If Image Works</tr>
</table>
`
)
in nodemailer configuration you must set attachment, example:
from: '"Orange Water" <123#orange.com>', // sender address
to: getEmail, // list of receivers
subject: subject,
html: data, // html body
attachments: [{
filename: 'image.png',
path: 'your path to image',
cid: 'unique#kreata.ee' //same cid value as in the html img src
}]
});
And in your html file, img src must the same cid which already declared in nodemailer configuration. example:
<p<img src="cid:unique#kreata.ee" width="100" height="100" </p>
Hope this help.
You have to set the full URL of the image in the src attribute.
<tr style="background:black"> <img src="https://yourdomain.com/img/logo.png"></tr>
I am using nodemailer for sending emails from my nodejs app. I am successfully able to send an email. But, if I want to send a link, the href or anchor tag is not working. That is the link does not go as part of the mail. The rest of the text is sent. Any ideas?
Here is the relevant code :
var messagebody = "Hello ".concat(req.body.name).concat(", One of your team mates have submitted an application form for intern next summer. Please approve or reject the same on the internship portal. Best Regards.");
var mailOptions = {
from: from, // sender address
to: to, // list of receiver
// cc: cc,
subject: subject, // Subject line
text: messagebody, // plaintext body
html: ' Hello '.concat(req.body.name).concat(' , <br /></br > One of your team mates have submitted an application for intern(s) for next summer. Please approve or reject the proposal on the internship portal. <br /> Here is the link of the internship portal : <br /><br /> Best Regards.') // html body
};
Your code is Correct but you havn't wrote anything in between <a></a> tags.
Just put some text between them and it will work.
Click here
You can also render a jade (or pug) file and get it as a string
const render = jade.compileFile('./views/my_email.jade');
const html = render(content);
const mailOptions = {
from: from, // sender address
to: to, // list of receivers
subject: subject, // Subject line
html: html
};
where content is the array with the data you want to pass to the jade file
Whenever I send a mail from netsuite, It goes in Rich text format (HTML format).
Instead, I want to send it in Plain text format.
I tried many ways but not working. even when I send it with just as a string it goes in HTML format.
E.g.:
var email_subj = "Mail Subject";
var mail_content = "This goes in Body";
nlapiSendEmail(1234,'abc#gmail.com',email_subj,mail_content ,null,null,rec_MailID);
The above mail too goes to the recipient in Rich Text Format.
Is there a way so that it goes in Plain text format.
To know whether the mail is in rich text or plain text you can inspect the body element in browser of the recipient and you will see that there are HTML contents in the mail body.
Or if you are using Outlook: you can right click the body content and there will be option called "View Source" if you click it you will see the HTML code.
Note: in outlook if the mail is in Plain text format then "View Source" option is disabled you cannot click on it, that is what i want.
SuiteScript 1.0 appears to wrap all email bodies in HTML tags.
SuiteScript 2.0 N/email module(ie: email.send() ) will format as plain text unless you include markup in the body. Mock code:
require(['N/email'],
function(email) {
function sendEmail() {
email.send({
author: 1234,
recipients: 'abc#gmail.com',
subject: 'Mail Subject',
body: 'This goes in Body',
});
}
sendEmail();
});