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.
Related
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.
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
I'm writing a bot in Node.js using the MS Bot Framework. To send attachments, I'm actually using the filestream buffer as the contentUrl, e.g.
...
var base64 = new Buffer(filedata).toString('base64');
var msg = new builder.Message()
.setText(session, text)
.addAttachment({
contentUrl: util.format('data:%s;base64,%s', contentType, base64),
contentType: contentType
});
session.send(msg);
...
where contentType is the proper mimetype for the file in question.
When I test this locally (using the Bot Framework Emulator), this works perfectly for both image and audio files - messages with image attachments display the image, and messages with audio attachments show the audiocard allowing for playback, etc.
However, when I test this through FB Messenger, the images work fine, but the audio messages just never appear in FB. Not even the text of the message comes through; it's like the entire message is lost. The dialogue simply skips over the message containing the audio attachment. I'm not even seeing any errors received server-side.
This is happening with both mp3 and wav test audio files, that are each under 1MB (smaller than many of the image files I've successfully tested).
Is there some trick to sending playable audio files to the FB Messenger channel specifically?
Thanks!
I wasn't (yet) able to get a response from FB support, but after further testing, it looks like there is a filesize limit on audio files FB Messenger will accept.
Specifically, I was able to get a sample file of ~45KB to send and display in Messenger successfully, but a larger file of ~400KB got dropped (aka seemed to send successfully from the server-side perspective, but did not show up in Messenger).
Strangely, some of my much larger image files went through, so it seems like this same limit does not exist for image attachments.
Will do some further testing, but it seems like the ultimate solution will be either to majorly compress my audio files, or to host them somewhere else instead of sending as a filestream.
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.
I'm creating an email app. To save time, I just download subject and some header and saved them to database, not download body of mail.
And then, If user click on subject, I will download body of this mail.
I try to use Message-ID (because it's unique) to make it is an index. and Using this code to find this mail on server
SearchTerm term = new MessageIDTerm(ID);
message_s = folder.search(term);
But it just success on GMAIL, some other server, this code doesn't work correct.
I try to get All message-ID and compare it on client side, It toke a lot of time to find, user can't wait too long to get body of email.
Anyone has an idea to find and download body of email correctly by Message-ID or by any header ?