"code for sending email above is the code .iam tired of scratching my head but still not able to see the image in the mail. I am converting the image into base 64 encoded string and also following the sendgrid syntax still not able to send the image .i dunno wats going wrong here.:"
var app = require("../../../server/server");
var base64Img = require("base64-img");
let status = null;
let textBody,
htmBody = null;
var DataSource = require("loopback-datasource-juggler").DataSource;
var dsSendGrid = new DataSource("loopback-connector-sendgrid", {
api_key: app.customConfig.mail.sendgrid.api_key
});
var fs = require("fs");
function base64_encode(file) {
var bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString("base64");
}
function base64_decode(base64str, file) {
var bitmap = new Buffer(base64str, "base64");
fs.writeFileSync(file, bitmap);
console.log(
"******** File created from base64 encoded string ********",
base64str
);
}
var base64str = base64_encode("../../../images/Campaign-images/Christmas.png");
let message = {
to: "somebody@gmail.com",
from: "noreply@gmail.com",
subject: "test",
text: "hi",
html: '<img src="cid:myimagecid"/>',
attachment: [
{
filename: "Christmas2.png",
content: base64str,
ContentId: "myimagecid"
}
]
};
console.log(message);
app.models.Email.send(message)
.then(result => {
return "sent";
})
.catch(err => {
console.log(err);
return "failed";
});