I'm using Mandrill in Nodejs to send emails to customers, and want to embed an image in my html content attached to the emails. I found some solutions from https://mandrill.zendesk.com/hc/en-us/articles/205582457-Tips-for-using-images-in-Mandrill-emails and decided to use the 4th one, which includes the image inline in the html. The code is as below:
var message = {
html: htmlContent,
subject: "Subject",
...
images = [{
"type": logo.logoType, // which is "image/jpeg"
"name": "logo",
"content": content // the content is valid when using in <img src="data:image/jpeg;base64,content"> directly
}]
};
mandrillClient.messages.send({
message: message
}, function() {
callback(null);
}, function(err) {
callback(err);
})
And the corresponding html code in htmlContent is
<img src="cid:logo">
However, when I checked with the sent email in Mandrill Outbound Activity, "View Content" doesn't show the image correctly. And I looked at the html source, found the image code was still as
<img src="cid:logo">
The plain text didn't get replaced by image data.
How can I get it work properly? Any ideas?
Thanks in advance.
Finally I found it just didn't work when checking the sent email in Mandrill Outbound Activity, but it works fine in your actual email inbox. So it means you will never see the embedded image when do testing, you must send it with production api key and see the results in a real email inbox.
Just FYI. Hope no one will waste any time on this like I did. :)
Related
I'm trying to implement a share button on my website, but I'm having problems with iOS Safari.
var title = "Subject";
var text = "Body";
var url = "https://google.com";
if (navigator.share) {
navigator.share({
title: title,
text: text,
// url: url,
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
}
else{
window.open("mailto:?subject="+encodeURIComponent(title)+"&body="+encodeURIComponent(text)+" "+encodeURIComponent(url), '_blank');
}
It works fine on android, but if I try to send an email from an iPad the subject is not set, and when I send the email the subject becomes the whole message. I suspect the iOS' mail app doesn't receive the data in the same way as the android's gmail app.
Is it a known issue? Is there a workaround?
Thank you!
If you only pass the title navigator.share({ title, }) you'll find that in Apple's Mail, it becomes the body of the email, not the subject. This is contrary to Gmail on Android which uses the title to populate the subject.
Unfortunately, the spec doesn't spell out how the title should be used:
title member The title of the document being shared. May be ignored by the target.
See this article for more nuances and examples of navigator.share in iOS/Mac OS.`
I'm playing around with the Twilio MMS API, and I'm wondering if there's a simple way to show a Gif attachment after the body text?
So far I've only been able to send the Gif before the text.
I understand the behavior you are talking about. I'm sure you've figured it out by now, but if not, here is a hack:
Send a blank text file first, which means put it last, as the files in this Twilio SMS/MMS (twiml too) are processed in reverse order.
Twilio Functions Example (node.js)
exports.handler = function(context, event, callback) {
var client = context.getTwilioClient();
let dataMMS = {
to: ['+15556667777'],
from: '+15551112222', // your twilio num
body: 'I am the body',
mediaUrl: [
'http://s3.amazonaws.com/blog.invisionapp.com/uploads/2014/12/motion-example.gif',
'https://sepia-jaguar-8734.twil.io/assets/blank.csv'
],
contentType: [
'image/gif',
'text/csv'
]
};
client.messages.create(dataMMS).then(function(response){
console.log('Message Sent : ' + response.status);
return callback(null, 200); //response.status, queued = good (200)
}).catch(function(err){
console.log('An error is happening: ' + err);
return callback(null, err);
});
}
Extra:
This gif link was selected from a random link https://www.invisionapp.com/blog/7-tips-for-designing-awesome-gifs/. It was selected because it was nice and small, ~25 kb.
In my testing with Twilio and my carrier, I found gifs < ~100 kb worked and if I remember correctly they are not run thru a compressor like png/jpegs.
Note to Twilio employee: The Twilio public asset is in a dummy sub account, I'd be happy to replace it with an asset not related to me.
Oh yeah, make sure your urls have proper mime type encoding: https://www.twilio.com/docs/api/messaging/accepted-mime-types
I think Twilio is forgiving for .jpg and .png , as they are run thru compressors...
ps This will give you an extra blank line in your text block, you can get rid of it. Share your answer when you discover how, cause I've shared enough today.
I have written a custom Slash command that takes in a query from the user and returns an image.
The Server side which receives the Slash command retrieves the query from the user, and forms the Image URL http://example.com/file1.png and it sends back the response as <http://example.com/file1.png>. This is shown as a link in the response and is not unfurled. What could be the problem?
I even tried the following:
1) I sent back a JSON payload as given below:
{
"text":"http://example.com/file1.gif","unfurl_media":true
}
But that displayed the link again and did not unfurl it.
2) I tried
{
"text":"<http://example.com/file1.gif>","unfurl_media":true
}
But same results.
What could be the problem? Do I absolutely need a incoming webhook integration and send the message there ?
Did it work the first time, or had the URL previously been unfurled?
Slack will only automatically unfurl a URL once per hour in a given channel. If a user manually posts the URL and it is not unfurled because of this limit they will get an ephemeral message from SlackBot about it, however the unfurl just silently fails for slash commands or webhooks. I've hit this before in testing and had to make sure to change either the URL or the channel to verify things are working.
You should not need a manual attachment or a webhook or even the unfurl_media flag in the response (it's on by default for messages posted via webhooks/slash command).
I was having a similar issue with slash commands returning the text of my image url.
What you need to change is to use an object with an image_url for your image, and put that inside an attachments array.
Below is an example that returns the link of the image as text and the image itself.
{
"parse": "full",
"response_type": "in_channel",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
{
"parse": "full",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
I'm trying to figure out how to render data that the server sends in an event. Let's say I write sse.write "test" or sse.write {name: "test"} to the browser. How would I be able to capture that into an element on the page? I know it can be viewed in curl... Could I implement that? I'm very new to rails.
You'll have to use JavaScript for this.
// app.js file loaded in the page
sse = new EventSource('localhost:3000/sse');
sse.addEventListener('message', function(e) {
text = document.createTextNode(e.data);
el.createElement('p').appendChild(text);
document.body.appendChild(el);
}, false);
I am new in using IMAP. Now I am trying to use IMAP to see my emails in my web page from mail server. I have configured the settings. And I think the configuration is ok. Now I want to show the message body as html format. My code is:
// getting email body text
if($attachments[1]['is_attachment']!=""){ // if attachmentavailable.
$part_number = '1.2';
}
else{
$part_number = '1';
}
$message = quoted_printable_decode(imap_fetchbody($inbox, $email_number, $part_number));
When email has attachment, it is showing as html format. But when there is no attachment the message is showing as plain text. There is no bold or any other formatted font if I give and there is no link also.
If I use part number 1.2 in else part no message is shown.
Now how can I print email message as html format where there is no attachment.
Learn about the BODYSTRUCTURE format. E-mails can come up in about a ton of different structures, and unless your application actually takes a look at the structure of the MIME message, your code is blindly guessing what to do.