Retrieve and display inline images from email when encoded as a CID with Ruby on Rails - email

I'm using Viewpoint to retrieve email from an Exchange server for creation of objects in a Ruby on Rails app.
I'm able to see that an image has been included, inline, in the body of an email, like so:
<img src=\"cid:94C552FB-8474-437C-AB44-DDF809047AB9\" type=\"image/png\">
And I can see an attachments node in the item blob, too:
:attachments=>{
:file_attachment=>{
:content_type=>{
:text=>"image/png"
},
:content_id=>{
:text=>"94C552FB-8474-437C-AB44-DDF809047AB9"
},
:attachment_id=>{
:id=>"AAMkAGEzNmExNzEzLTcxMjEtNDM5YS04NmE0LWE0NWU3MWZiMjEwNgBGAAAAAAB4VZcbdHrATrbGrKL0ANCfBwCjSVkOjPEtQoJN3xOKeIYJAAzyZ5e9AACjSVkOjPEtQoJN3xOKeIYJAA25w05NAAABEgAQAK9ad+6BP7VHru83AO7CTrU="
},
:name=>{
:text=>"Hollowbody 2.png"
}
}
}
My question is, how do I turn any of this into a URL suitable for use as the src of an img tag? I've seen answers like this one, but they appear to have special privileges in that
They're running in C#, which has special understanding of Exchange and the way it handles resource (I assume)
They appear to be running on the same server as Exchange, and have access to the same tmp directory where attachments are held.
If you're on another machine in another language, how do you get to these images? I know it's possible, since there are email clients on everything from mobile phones to refrigerators that can receive emails from Exchange/Outlook and render the imageā€¦

Related

Delphi - Using resource in Email rather than image

In Delphi, I create emails in HTML using the following code to display a signature in the message:
cMsg:= cMsg + ' <img src="BarrysSignature.jpg" '>
Which means I need to have the .jpg available in the current directory (and distribute it with the executable).
I also use these same signature .jpg files elsewhere in my program, but I've loaded them as resources. What would be better in the emails is if I used the resource for the signature in the email, rather than the external .jpg picture.
I've tried a few ways of doing this but can't get it working. Any thoughts, please?
Similar to #Dmitry's answer, in Indy you would also need to attach the image data to an email (the TIdMessage component), assign the attachment's Content-ID header (the TIdMessagePart.ContentID property), and then refer to that ID in the HTML using a cid: URL where needed.
Refer to these blog articles on Indy's website for how to do this:
HTML Messages
New HTML Message Builder class
I do want to mention one thing, though. Where the articles talk about using TIdAttachmentFile for attachments, you actually don't need to save your image resource to a temporary file at all in this situation. You can alternatively derive your own class from TIdAttachment (let's call it TIdAttachmentResource), and have it override the virtual OpenLoadStream() and CloseLoadStream() methods to return/free a TResourceStream to your resource data, respectively (see the source codes for TIdAttachmentFile and TIdAttachmentMemory for examples). Then you can simply add TIdAttachmentResource objects to the TIdMessage.MessageParts collection as needed, and Indy will be able to encode the email using the image resource directly, no file needed.
In Outlook, you will need to extract the resource to a temporary file, add the image as an attachment, set its PR_ATTACH_CONTENT_ID MAPI property, delete the file. Your HTML body would need to reference the image by its content-id, e.g. <img src="cid:xyz">, where "xyz" is the value of the PR_ATTACH_CONTENT_ID property.
See Including Pictures in an Outlook Email

Outlook Show Email Images to User

I'm trying to send mails to some users which are basically built over images. How can I get those images to download by default in the users' (outlook) mailbox?
I did try encoding the image in base64 and sending it, not as a hosted image but embedded in email-html. But that too, did not work :( (I was SO sure that it would)
The client (organization) is well aware of this (that we'll be exchanging mails). Is there any setting that can be tweaked in the admin panel of MSExchange or o365 which can allow this?
Users have to have that set in their preferences. You cannot make it automatically do it as an email sender due to SPAM senders and security reasons.
Outlook allows adding hidden attachments, you may refer mention they in the message body (embedded images). In the message body you may see the following tags:
<img src="cid:some-image-cid" alt="img" />
The "cid:" prefix means that name refers to the attached image with the specified content ID.
Attachment attachment = newMail.Attachments.Add(
#"E:\Pictures\image001.jpg",
OlAttachmentType.olEmbeddeditem, null, "Some image display name");
string imageCid = "image001.jpg#123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);
String.Format("<body><img src=\"cid:{0}\"></body>", imageCid);

URL links in email - resolve correct url?

Before i start thinking about this programatically, does anyone know if it is possible to actually extract the correct url from an email link that is basically a tracking module?
Our work email system auto blocks tracking based urls from email, so i am thinking of writing something to extract the correct url so people can copy and paste the tracking link into a program and it will provide the correct url.
Is this even possible with the way that email tracking works?
Here is an example of a url in an email that i recently received:
http://t.dripemail2.com/c/eyJhY2NvdW50X2lkIjoiNTE0MTQ4NSIsImRlbGl2ZXJ5X2lkIjoiOTI0NzI2MTU0IiwidXJsIjoiaHR0cHM6Ly93d3cuYXhzaWVkLmNvbS9nY3NlLWNvbXB1dGVyLXNjaWVuY2Uvb2NyLW5lYS1ndWlkZS8_X19zPXphb2txcDVpaWN4NGkxZndtYmNnIn0
Our system blocks these. It eventually resolves to:
https://www.axsied.com/gcse-computer-science/ocr-nea-guide/?__s=zaokqp5iicx4i1fwmbcg
(got our network admin to check it for me)
I want a system that gets the right url from the ugly mess that is blocked so we can actually view links from emails.
Thanks in advance for any help.
The data in tracking URLs are typically a unique ID pointing to some entry in a database, or are encrypted with a private key, so there's no way to obtain any meaningful information from them. (see answers to this related question: Generate unique link for each website visitor)
More naive approaches will simply encode the data, in which case you may be able to extract useful information from them. Funnily enough, your example URL is a base 64 encoded JSON object containing the link itself:
{
"account_id": "5141485",
"delivery_id": "924726154",
"url": "https://www.axsied.com/gcse-computer-science/ocr-nea-guide/?__s=zaokqp5iicx4i1fwmbcg"
}
In this case you could actually resolve the URL on your own, but this type of approach is uncommon for that very reason.

Detecting image load on server

I am wondering how services like mailchimp detect email opens
I read it's because they add a 1x1 pixel image
Can someone tell me how this is done on my server ? I am using AWS :)
I would also like to know how these services detect things like device and browser/email client
I read it's because they add a 1x1 pixel image
True
Can someone tell me how this is done on my server ? I am using AWS :)
The usual approach is to set the image source attribute to a URL on your web server that includes a query string parameter that you can track back to a particular user, for example a hash of the user's email address or their ID in your system, e.g. in the email you send you add a tag like this
<img src="http://example.com/track?id=42 width="1" height="1" />
That forces the email client to load the URL http://example.com/track, which would return a 1x1 transparent image and also log that the ID 42 requested that image.
Note that some email clients block images from some domains. If the user has you in their contacts list, chances are pretty good the image will be shown. Some ISPs will consider your sending reputation, your implementation of email security standards (e.g. SPF/DMARC) and other factors in deciding whether to actually request and display the pixel data.

How to set up an email server that will accept a URL in the subject of an email and respond with a copy of that webpage

I'm trying to piece out how difficult it would be to set up an email server that will accept a URL as the subject of an email and respond with an attached copy of said webpage, or element(s) of that webpage (ie, an image from the page, or all of the videos on the page).
I don't necessarily need the code written for me, but would appreciate if someone could suggest a starting point.
I have very little web-programming knowledge (some C++, some Actionscript), which is partly why I don't even know where to begin.
There is several ways to achieve this.
In most unix MTAs you can set up an alias to pipe all messages for some address through a program.
This program need to parse the message header for the "from" and "subject", fetch the url and sent it back.
You can also do this with a program like fetchmail, so you dont even need to make something in the server side.
Finally, several languages have wonderful libraries fetch the mail using POP3, parse it, fetch the URL from the subject and compose a new mail message. Should be no more than 100 code lines with perl or python.