How to send large files with Nodemailer? - node.js

I'm building a website where people can buy songs, and when they do, they get an email with the song in attachments
I'm using Nodemailer for that with that "attachments" option
attachments: [
{
filename: req.body.purchasedSongName,
path: path.join(__dirname, `../uploads/prods/songs/${req.body.purchasedSong}`),
contentType: 'audio/mpeg'
}
]
The problem is that when the song is too large (25MB+ apparently) Gmail gives me an error:
Error: Message failed: 552-5.2.3 Your message exceeded Google's message size limits.
What solutions do I have to fix that?

Simple: Don't send the file via email.
Instead, just send a link from where your users can download the song. You could also implement a system where one download link is usable exactly once, or for a limited time.

Related

Send to kindle using nodejs

I'm trying to adhere to https://www.amazon.com/gp/help/customer/display.html/ref=hp_pdoc_main_short_us?nodeId=200767340&ref_=pe_1825130_138612630
I have text stored as HTML in the database. I sent an attachment using sendgrid to username#kindle.com, but Amazon refuses to recognize this attachment as a HTML file. I don't know what to do.
var body = {
subject: book.title + " test Original",
personalizations:
[{
to: [{email: to,}]
}],
content: [{type: "text/plain", value: book.title + " book summary"}],
from: {email: 'info#test.com', name: 'test Team'},
attachments: [
{
filename: book.id + ".html",
content: btoa(book.body),
type: 'text/html',
disposition: 'attachment'
}
]
};
this._sendEmail(body);
I'm trying to send HTML documents to user's kindles to be read on their kindle.
I get this error from amazon
The Kindle Personal Document Service can convert and deliver the following types of documents:
Microsoft Word (.doc, .docx)
Rich Text Format (.rtf)
HTML (.htm, .html)
Text (.txt) documents
Archived documents (zip , x-zip) and compressed archived documents
Mobi book
Images that are of type JPEGs (.jpg), GIFs (.gif), Bitmaps (.bmp), and PNG images (.png).
Adobe PDF (.pdf) documents are delivered without conversion to Kindle DX, Second Generation and Latest Generation Kindles.
Adobe PDF (.pdf) can be converted to Kindle format and delivered on an experimental basis.
If the document that failed belonged to one of the above document types, please ensure the document is not password protected or encrypted. Note that the Latest Generation Kindles support password protected PDFs.
Helpful tips for personal document attachments:
The file size of each attached personal document should be less than 50MB (before compression in a ZIP file)
The email submitted should not contain more than 25 attached personal documents
You can learn more about transferring personal documents to your Kindle in our help pages:
http://www.amazon.com/kindlepersonaldocuments/
If you would like immediate assistance, please contact customer support at +1-866-321-8851 (US customers) or +1-206-266-0927 (International Customers).
Sincerely,
Amazon Kindle Support
Please Note: This e-mail was sent from a notification-only address that cannot accept incoming e-mail. Please do not reply to this message.
Learn more about Amazon Kindle
Check out the Kindle Store
If you have further questions about Kindle, please visit the Amazon Kindle Help pages
The Help pages will provide you with answers to common questions and provide you with a direct link to Amazon Kindle specialists.
To contact Amazon Kindle Customer Service, simply click a button in the Contact Us box on the Help pages to receive assistance by e-mail or phone.
Reading your personal documents on Kindle is now easier than ever. Learn more about "Send to Kindle" at www.amazon.com/sendtokindle

How to use Twilio to send customized PDF’s from Google Drive/Sheets

I am having problems trying to send customized PDFs from Google Drive to users on WhatsApp using Twilio’s API.
I am using node.js and the documents are created in Google Sheets and stored in Google Drive.
client.messages
.create({
mediaUrl:['https://drive.google.com/uc?id=INSERT_FILE_ID&export=download'],
from: 'whatsapp:+14155238886',
body: `It's taco time!`,
to: 'whatsapp:+15017122661'
})
.then(message => console.log(message.sid));
I thought it would be possible to send the PDF by passing the PDF’s Drive link through MediaURL as that is what is recommended on Twilio’s site for sending media (Images, .mp3’s and PDF’s) but when I try that it doesn’t work.
NB: it works when I try image URL’s etc.
I have tried sending the webContentLink of the PDF that also doesn’t work.
example: how the pdf should look when sent
I do not want to send the user a normal link for them to leave WhatsApp.
Any help with this or any other method to achieve this would be greatly appreciated.
Twilio will check the content-type of the file which you have been passing in the mediaUrl parameter. Twilio will reject if the content-type headers of your media attachment do not match the file extension (for example, content-type is image/jpg but the file extension is .png). It specified in the following links specifies:
Twilio Troubleshooting
Twilio supported-mime-types

Unable to send pdf file from bot to user in ms teams

NodeJS BotBuilder SDK version: 3.15.0
My code:
var pdf = {
name: '<file_name>.pdf',
contentType: 'application/pdf',
contentUrl: '<https url to public pdf file>'
};
var reply = new builder.Message(session).addAttachment(pdf);
session.send(reply);
This code is the same in few online examples. The issue I have is that I always get error:
Error: POST to 'https://smba.trafficmanager.net/emea/v3/conversations/a%3A1TwHmhoGuZP2Mf9P0TTnjv8HkcaXzEHryv0sYCvDDUI-qrMitJtHRlAnIcedcDH_v3IfMBXtg_zo5MDVcS0-8hDCQ4sJzpJhrewBPK8uWJXYeShgmd-s7uh5o8kW4ebAP/activities/1543588440246' failed: [400] Bad Request
For image/png this code works fine.
What I want to achieve is this: (image is taken from Bot Framework Emulator)
File from the web sent from bot to user
The file is sent from bot without uploading it to users's one drive.
This works also when I tested the feature in test section of https://dev.botframework.com/bots. It doesn't work only in ms teams.
The behaviour for sending files can differ per channel. Microsoft Teams doesn't support the direct upload method, like the WebChat / Emulator does. This is due to compliance reasons, as Bill Bliss stated.
You can post messages with card attachments referencing existing SharePoint files using the Microsoft Graph APIs for OneDrive and SharePoint. Using the Graph APIs requires obtaining access to a user's OneDrive folder (for personal and groupchat files) or the files in a team's channels (for channel files) through the standard OAuth2 authorization flow. This method works in all Teams contexts.
Have a look at Send and receive files through your bot
for the full documentation and how to implement.
An alternative option would be to use an AdaptiveCard where you can use an image thumbnail of the document combined with a button to directly download the PDF file from your public accessible URL.

Sending existing messages with the gmail API

I'm trying to write a script that uses the gmail API to forward messages from my inbox to new recipients.
This guide recommends sending the base64 encoded string for the e-mail. Presumably, I could get the existing e-mail using the get method with format=raw, edit the base64 encoding to change the recipients, and send the new message along.
The messages I'm sending are quite large (many attachments), so this process (of downloading a massive base64 string, decoding it, doing some regex substituion, re-encoding it, and then re-uploading it) will take a long time. It also seems very cumbersome to use regex to manipulate a MIME email message.
It seems that there should be an easier way...? Perhaps some way to do this directly via the API?
Try to use the MailApp.sendEmail(). You can use that script to send to multiple receivers so sending messagees to many people wont be that cumbersome.
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
MailApp.sendEmail('a#example.com,b#example.com,c#example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
If you want additional samples, try this SO thread.

Slack bot send an image

I am developing a bot for slack. I am implementing a notification functionality, where it will send a notification for every one hour. Currently, I am sending normal text in notification, but I need to send an image along with text. Is it possible to send an image?
You can send images as part of the attachments of a message. That can be either a full image or a thumbnail.
Just add the image_url property for full images or the thumb_url property for a thumbnail image with a url to an image to your attachment and it will be displayed under your message. You can also send multiple images through adding multiple attachments.
Example attachment: (based on official Slack documentation example)
{
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"text": "Optional text that appears within the attachment",
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png"
}
]
}
This works with all approaches for sending message, e.g. API method, Incoming webhook, response to slash commands etc.
See here for the official Slack documentation for attachments.

Resources