email is going empty when attaching an image with it - javascript

let message = {
to: toEmail,
from: liveCampaign.emailFromAddress,
subject: liveCampaign.emailSubjectTemplate,
text: "hi",
html: '<img src="content_id:myimagecid" alt = "graphics">',
files: [
{
filename: "Christmas2.png",
content: ("image" | Buffer),
content_id: "myimagecid",
contentType: "image/png"
}
]
};
i have modified my code but still not able to send the mail .i am getting response error from sendgrid, please somebody help me can somebody provide a syntax of email with attachment in sendgrid

Related

How to upload contentBytes chunk by chunk on Graph url return by createUploadSession graph API?

As per microsoft graph API documentation the createUploadSession graph API only return the URL where attachment can upload but how to upload attachment chunk by chunk in javascript? does anyone knows? Thanks in advance.
I'm referring this reference
Here is the reference for attaching the Attachment to a post in JavaScript, Please refer this Document
const options = {
authProvider,
};
const client = Client.init(options);
const reply = {
post: {
body: {
contentType: 'text',
content: 'Which quarter does that file cover? See my attachment.'
},
attachments: [{
'#odata.type': '#microsoft.graph.fileAttachment',
name: 'Another file as attachment',
contentBytes: 'VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQu'
} ]
}
};
await client.api('/groups/1848753d-185d-4c08-a4e4-6ee40521d115/threads/AAQkADJUdfolA==/reply')
.post(reply);
Hope this helpful.

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

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

Use Mailgun to send a pdf attachment from Base64 string

I have a pdf that is being generated by another function, which returns a Base64 string. I would like to then attach it to a Mailgun email as attachment, which is built into Meteor and Mailgun. I see that there is a lot of examples of attaching a file from the file system, but I don't see anything using Base64.
I have a method that generates a Base64 string and concatonates with prefix in order to convert Base64 to PDF:
//returns base64 string: looks like "YW55IGNhcm5hbCBwbGVhc3VyZQ=="
const base64AttachmentString = 'data:application/pdf;base64,' + generatePdfBase64();
import { Email } from "meteor/email";
Email.send({
to: "email#example.com",
from: "John Smith <johnsmith#example.com>",
subject: "Sending Base64 as PDF",
html: generatedHTMLTemplate,
attachment: base64AttachmentString
});
Is there a way to send a Base64 attachment where Mailgun will recognize it as a PDF? I know this is possible with other mailers such as Nodemailer and SendGrid.
It seems like meteor's Email requires you to add the attachments keys, which should be an array of attachments.
As for the options for the attachments - there are multiple:
{ // utf-8 string as an attachment
filename: 'text1.txt',
content: 'hello world!'
},
{ // binary buffer as an attachment
filename: 'text2.txt',
content: new Buffer('hello world!','utf-8')
},
{ // file on disk as an attachment
filename: 'text3.txt',
path: '/path/to/file.txt' // stream this file
},
{ // filename and content type is derived from path
path: '/path/to/file.txt'
},
{ // stream as an attachment
filename: 'text4.txt',
content: fs.createReadStream('file.txt')
},
{ // define custom content type for the attachment
filename: 'text.bin',
content: 'hello world!',
contentType: 'text/plain'
},
{ // use URL as an attachment
filename: 'license.txt',
path: 'https://raw.github.com/andris9/Nodemailer/master/LICENSE'
},
{ // encoded string as an attachment
filename: 'text1.txt',
content: 'aGVsbG8gd29ybGQh',
encoding: 'base64'
},
{ // data uri as an attachment
path: 'data:text/plain;base64,aGVsbG8gd29ybGQ='
}
Specifically in your example you can use:
const base64AttachmentString = 'data:application/pdf;base64,' + generatePdfBase64();
import { Email } from "meteor/email";
Email.send({
to: "email#example.com",
from: "John Smith <johnsmith#example.com>",
subject: "Sending Base64 as PDF",
html: generatedHTMLTemplate,
attachments: [
{
path: base64AttachmentString
}
]
});

dpd-email / nodemailer wont attatch file

Trying to att. a file using dpd-email (its using nodemailer)
by examples in nodemailer (https://github.com/andris9/Nodemailer#attachments)
This just gives me a file of 'attachment-1.bin' 0kb of size
tried using diffrent post examples from the nodemailer site, but same result.
Using chrome postman
http://localhost:99/email
to:"asa#me.me"
subject: "test"
text: "test"
attachments: [
{filename: "test.tx"', content:"hello world", contentType:"text/plain"}
]
In NodeMailer, attachments is an array of attachment objects. In your above code snippet though, you're setting attachments to an object instead of an array.
Taken directly from E-mail Message Fields
attachments - An array of attachment objects
Change
attachments: {
filename: 'text.bin',
content: 'hello world!',
contentType: 'text/plain'
}
To
attachments: [
{
filename: 'text.bin',
content: 'hello world!',
contentType: 'text/plain'
}
]

Categories

Resources