Hyperlink not shown in gmail with email composer - javascript

I am trying to send html as a body with email composer. html body contains hyperlink but it is not working in gmail. Gmail display plain text only.
var email = {
to: sendersemail+';',
cc: '',
bcc: '',
attachments: [cordova.file.externalApplicationStorageDirectory+'Report.pdf'],
subject: '',
body: '<p>the brain out your I think you'll find it helpful too.</p>',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});

use html instead of body!
var email = {
to: sendersemail+';',
cc: '',
bcc: '',
attachments: [cordova.file.externalApplicationStorageDirectory+'Report.pdf'],
subject: '',
html: '<p>the brain out your I think you'll find it helpful too.</p>'
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});

Related

Can’t Attach PDF File to Email in JavaScript Using smtpjs

Summarize the problem
I am unable to attach a PDF file to an email to be sent to an email address. The PDF file is in the same folder as the HTML file, which contains the JavaScript code to send the email using SMTPJS.
Expected result:
An email is sent to the designated email address with the pdf file without any problems.
Actual result:
No email was sent at all.
Describe what you’ve tried
#1: Attempt by putting file name and extension in quotes like this:
PFD_Articles.pdf -> 'PFD_Articles.pdf'
Again, the actual result is produced, not the expected one.
Show some code
Email.send
(
{
Host: "smtp.gmail.com",
Username: "sender#gmail.com",
Password: "password",
To: 'receiver#gmail.com',
From: "sender#gmail.com",
Subject: "<h1> ddd </h1>",
Body: "And this is the body",
Attachments:
[
{
name: 'PFD_Articles.pdf'
}
]
}).then
(
alert("Successful! Please check your email inbox. Otherwise, you may have to enter your email address again.")
);
Email.send({
Host: "smtp.gmail.com",
Username : "abc#gmail.com",
Password : "abc",
To : receiver,
From : "abc#gmail.com",
Subject : emailSubject,
Body : emailBody,
Attachments : [
{
name : list.pdf
data : pdfBase64
}]
}).then(
)
});
This worked ! The created pdf got added to the email as an attachment

Sending emails on behalf of someone using nodemailer

I'm trying to send an email on behalf of my user using nodemailer but all my emails are being rejected.
My transporter works for normal use-cases where I'm sending from my own domain:
const transporter = nodemailer.createTransport({
host: 'emailhost.com',
port: 465,
secure: true,
auth: {...},
dkim: {
domainName: <domainname>,
keySelector: <keyselector>,
privateKey: <privatekey>,
},
});
transporter.sendMail({
subject: "Shop subject",
from: `kyle#mydomain.com`,
to: <customerEmail>,
replyTo: <shopEmail>,
html: "<div>my user message</div>",
})
But when I try to send on behalf of my user it doesn't work:
transporter.sendMail({
subject: "Shop subject",
from: `shop#exampleshop.com`,
to: <customerEmail>,
// sender: `kyle#mydomain.com` <-- Also tried adding this field,
replyTo: `shop#exampleshop.com`,
html: "<div>my user message</div>",
})
>> "Can't send mail - all recipients were rejected: 553 <shop#exampleshop.com>: Sender address rejected: not owned by user kyle#mydomain.com"
I figured if I set a DKIM DNS record and an SPF record on exampleshop.com it would mean I could send emails on behalf of the domain but still no luck.
Type: TXT Record
Host: #
Value: v=spf1 include:spf.emailhost.com ~all
// Also tried adding this record in place of the one above
Type: TXT Record
Host: #
Value: v=spf1 include:spf.mydomain.com ~all
Type: TXT Record
Host: default._domainkey
Value: v=DKIM1;k=rsa;p=<DKIM DNS record from namecheap>
It's also been over an hour since I've updated the DNS records, I'm not sure what I'm doing wrong here.
try using the envelope for this. as i understand it, "envelope" values are like whats written on the outside of a physical piece of mail. it tells the post office where to actually send (or return) the message. the "header from", on the other hand, is like when you re-write your address at the top of the piece of paper that comes inside the envelope. it doesn't do anything but it looks nice.
header_from = "it-just-looks-like-its-from-me#asdf.com"
envelope_from = "im-actually-doing-the-sending#asdf.com"
to = 'pick-me#asdf.com'
var mailOptions = {
from: header_from,
to: to,
subject: 'Sending Email using Node.js',
text: 'That was easy!',
envelope: {
from: envelope_from,
to: to,
}
};
https://nodemailer.com/smtp/envelope/

How to send images and hyper links via smtpjs?

I have the following code:
const input = document.querySelector('input')
btn.addEventListener('click',() => {
Email.send({
Host: 'smtp.gmail.com',
Username:'',
Password:'',
To:input.value,
Subject:"",
From: '',
Body:''
}).then(msg=>console.log(msg))
And in the body I want to send a photo, on the next row text and then a hyperlink(or even the button) Is it possible or smtpjs does not provide that functuonality? Couldn't find anything
Or maybe there is another source(not smtpjs), where I could write a template of the letter and then send it
To send the files, you can define the attachment.
Email.send({
SecureToken : "<your security token>",
To : '<whom you want to send>',
From : "<Your email id registered on SMTPJS>",
Subject: "<Subject>",
Body: "<Body Content>",
Attachments:
[{
name: "File_Name_with_Extension",
path: "Full Path of the file"
}]
})
.then(function (message) {
//
}
Next, if you want to send the hyperlink, I think you can use the html content on body instead of text.
...
Body: "Click <a href='[full_path of link]'>here</a> <button>Button</button>",
...
But the onClick event or other javascript actions will not work for button.
Thank you

Batch emailing with Mailgun and Node.js

I'm using the Mailgun node.js module to send batch emails out.
According to the big yellow warning message in the official docs, specifying recipient vars should result in sending "each recipient an individual email with only their email in the to field."
However, my recipients can see all of the "to" addresses. I am successfully using recipient-vars to set the email subject for users, so it does appear that these are being read in correctly.
Note that I am sending an HTML email using MIME. I tried this with the more straight-forward plain text variation, and it did appear to work.
Is anyone able to help me understand why my recipients can see all other recipients? Am I doing something wrong, or does this functionality not work for Mailgun MIME emails?
// recipients
var recipients = ['email1#email1.com', 'email2#email2.com', 'email3#email3.com'];
var recipientVars = {
'email1#email1.com': {
id: 1,
subject: 'Subject 1'
},
'email2#email2.com': {
id: 2,
subject: 'Subject 2'
},
'email3#email3.com': {
id: 3,
subject: 'Subject 3'
}
};
// options
var options = {
from: 'Me <me#me.com>',
to: recipients,
'recipient-variables': recipientVars,
subject: '%recipient.subject%',
text: myMailText,
html: myMailHTML,
headers: {
'X-Mailgun-Recipient-Variables': JSON.stringify(recipientVars)
}
};
// create mail
var mail = new nodemailer(options);
// send mail
mail.compile().build((err, message) => {
var mailData = {
to: recipients,
message: message.toString('ascii'),
'recipient-variables': recipientVars
};
mailgun.messages().sendMime(mailData, (err, res) => {
console.log(res);
});
});
Seems this functionality doesn't work with sendMime() method, but it does with regular send() method even without any mail compilation. Here is working code snippet:
const mailgun = require('mailgun-js')({
apiKey: 'api_key',
domain: 'domain'
});
const recipients = ['email1#gmail.com', 'email2#gmail.com'];
const recipientVars = {
'email1#gmail.com': {
id: 1,
subject: 'Subject 1',
name: 'Name 1'
},
'email2#gmail.com': {
id: 2,
subject: 'Subject 2',
name: 'Name 2'
}
};
const envelope = {
from: 'Sender <sender#gmail.com>',
to: recipients,
subject: '%recipient.subject%',
html: 'Hey <strong>%recipient.name%<strong>',
'recipient-variables': recipientVars,
};
mailgun.messages().send(envelope, function (error, body) {
console.log(body);
});
As you would notice all placeholders are populated and <strong> tag properly rendered.

How to fill Cordova Email Composer fields with variables

I am trying to use Cordova plugin called Email Composer to let users send emails. Cordova Email Plugin
I am generating some html content and want to prefill body of the email with the content.
The code I have tried:
function emailHtml(text) //variable to fill the body
{
cordova.plugins.email.isAvailable(
function (isAvailable) {
cordova.plugins.email.open({
to: 'your#email',
cc: 'second#mail',
bcc: [],
subject: 'Greetings',
body: text //the HTML content
});
}
);
}
But it does not work yet.
What is the proper way to use variables for the plugins fields?
Thanks.
You can actually do it by plain Javascript , No need to add additional plugin and increase the build size
let Link="mailto:someone#example.com?subject=Hello%20again";
window.open(Link, "_system");
You can add all the parameter you need in the link.
You need to use parameter isHtml: true
myHTML="<html> ......... </html>";
cordova.plugins.email.isAvailable(
function (isAvailable) {
cordova.plugins.email.open({
to: 'your#email',
cc: 'second#mail',
bcc: [],
subject: 'Greetings',
body: myHTML, //the HTML content
isHtml: true // indicats if the body is HTML or plain text
});
}
);

Categories

Resources