dpd-email / nodemailer wont attatch file - javascript

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'
}
]

Related

Deleting images in Imgbb via API

i'm using the imgbb API since it is very straghtforward to use and quite cheap. The problem is that the documentation is very poor and it does not explain how to delete an image through the API. I want to be able to delete the photo from my server in the case something happens (ex. if I delete a user).
My server is written in node.js.
pd. Also the response object I get after uploading an image is this one:
{
data: {
id: 'c3VRs4x',
title: 'client1-Bali',
url_viewer: 'https://ibb.co/c3VRs4x',
url: 'https://i.ibb.co/Pj0JVqt/client1-Bali.jpg',
display_url: 'https://i.ibb.co/1QjB4Fb/client1-Bali.jpg',
size: 60385,
time: '1594835546',
expiration: '0',
image: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/Pj0JVqt/client1-Bali.jpg'
},
thumb: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/c3VRs4x/client1-Bali.jpg'
},
medium: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/1QjB4Fb/client1-Bali.jpg'
},
delete_url: 'https://ibb.co/c3VRs4x/b3072de2f5287a39f81c7dec3cd8a236'
},
success: true,
status: 200
}
Edit: Here is the link to the imgbb API documentation: https://api.imgbb.com/
Imgbb does not allow you to delete images. I just tried going to the delete URL to delete the image and the image got deleted on that page but not on the other links in the JSON. If the functionality is not implemented on the site itself there is no use trying on the API. If they did have the functionality to entirely delete an image then you could have used web scraping to press the buttons.

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
}
]
});

React Native - Open mail client with body

I'm using npm pacakge to open mail client with data:
https://www.npmjs.com/package/react-native-mail-compose
Also, I'm using their example:
import MailCompose from 'react-native-mail-compose';
// later in your code...
async sendMail() {
try {
await MailCompose.send({
toRecipients: ['to1#example.com', 'to2#example.com'],
ccRecipients: ['cc1#example.com'],
bccRecipients: ['bcc1#example.com', 'bcc2#example.com'],
subject: 'This is subject',
text: 'This is body',
html: '<p>This is <b>html</b> body</p>', // Or, use this if you want html body. Note that some Android mail clients / devices don't support this properly.
attachments: [{
filename: 'mytext', // [Optional] If not provided, UUID will be generated.
ext: '.txt',
mimeType: 'text/plain',
text: 'Hello my friend', // Use this if the data is in UTF8 text.
data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text.
}],
});
} catch (e) {
// e.code may be 'cannotSendMail' || 'cancelled' || 'saved' || 'failed'
}
}
and call this function on button press. All data is OK, except body, for example here in Subject there is "This is subject", in CC of mail clients, there is "cc1#example.com", but body is always empty, I can't ever see "This is body" in mail client.
I've fixed it with another package react-native-send-intent.
It works like a charm! :)
I see, give this package a try.
https://github.com/anarchicknight/react-native-communications
Its very simple to use

email is going empty when attaching an image with it

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

Creating an envelope from a template returning "UNSPECIFIED_ERROR"

When I try to create an envelope from a template I get a response of:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
Here's what I'm doing so far:
First I login, which returns
{ loginAccounts:
[ { name: '*****',
accountId: '*****',
baseUrl: 'https://demo.docusign.net/restapi/v2/accounts/******',
isDefault: 'true',
userName: '***** ********',
userId: '*******-*****-*****-*****-*********',
email: '********#*******.com',
siteDescription: '' } ] }
So then I take the baseUrl out of that response and I attempt to create the envelope. I'm using the hapi framework and async.waterfall of the async library, so for anyone unfamiliar with either of these my use of the async library uses the next callback to call the next function which in this case would be to get the url for the iframe, and with our usage of the hapi framework AppServer.Wreck is roughy equivalent to request:
function prepareEnvelope(baseUrl, next) {
var createEntitlementTemplateId = "99C44F50-2C97-4074-896B-2454969CAEF7";
var getEnvelopeUrl = baseUrl + "/envelopes";
var options = {
headers: {
"X-DocuSign-Authentication": JSON.stringify(authHeader),
"Content-Type": "application/json",
"Accept": "application/json",
"Content-Disposition": "form-data"
},
body : JSON.stringify({
status: "sent",
emailSubject: "Test email subject",
emailBlurb: "My email blurb",
templateId: createEntitlementTemplateId,
templateRoles: [
{
email: "anemailaddress#gmail.com",
name: "Recipient Name",
roleName: "Signer1",
clientUserId: "1099", // TODO: replace with the user's id
tabs : {
textTabs : [
{
tabLabel : "acct_nmbr",
value : "123456"
},
{
tabLabel : "hm_phn_nmbr",
value : "8005882300"
},
{
tabLabel : "nm",
value : "Mr Foo Bar"
}
]
}
}
]
})
};
console.log("--------> options: ", options); // REMOVE THIS ====
AppServer.Wreck.post(getEnvelopeUrl, options, function(err, res, body) {
console.log("Request Envelope Result: \r\n", JSON.parse(body));
next(null, body, baseUrl);
});
}
And what I get back is:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
From a little googling it look like 'Non-static method requires a target.' is a C# error and doesn't really give me much indication of what part of my configuration object is wrong.
I've tried a simpler version of this call stripping out all of the tabs and clientUserId and I get the same response.
I created my template on the Docusign website and I haven't ruled out that something is set up incorrectly there. I created a template, confirmed that Docusign noticed the named form fields, and created a 'placeholder' templateRole.
Here's the templateRole placeholder:
Here's one of the named fields that I want to populate and corresponding data label:
As a side note, I was able to get the basic vanilla example working without named fields nor using a template using the docusign node package just fine but I didn't see any way to use tabs with named form fields with the library and decided that I'd rather have more fine-grained control over what I'm doing anyway and so I opted for just hitting the APIs.
Surprisingly when I search SO for the errorCode and message I'm getting I could only find one post without a resolution :/
Of course any help will be greatly appreciated. Please don't hesitate to let me know if you need any additional information.
Once I received feedback from Docusign that my api call had an empty body it didn't take but a couple minutes for me to realize that the issue was my options object containing a body property rather than a payload property, as is done in the hapi framework.

Categories

Resources