Can you and how do you embed images in an email when using the Gmail API? - email

When creating a message and using it to create a draft or email using the Gmail API, can you have an image embedded in the body? I'm looking to have the image data actually embedded similar to how copying and pasting an image (the actual data, not the link) into a Gmail email will place the image right in the content.
Can it be done like this or do I need to upload the image to some other location and use HTML to embed the image in the email? Any pointers on how to do it?

The short answer is that you would do this the same way you would for any email service.
The long answer is that you need to create a multipart/related message, where one part is the HTML content of the email and the other part is the image. The image part contains a Content-ID header that specifies an ID for the image, and the HTML image tag references that ID in the src attribute using the format cid:ID_HERE.
An example of how to construct such an email in Python is here: https://stackoverflow.com/a/1633493
P.S. - A great way to see how emails are constructed is to look at the raw message. You can look at the raw message for a given email in Gmail by clicking the drop down arrow next to the message and selecting "Show original".

Related

Power Automate sync/download to Dropbox file at URL link in email

I am trying to create a Power Automate flow that automatically syncs to Dropbox a file contained at a URL link in emails.
The email is always from the same email address, let's say: "example#example.com"
The URL link always has the same hyperlinked text: "Link to Signed Affidavit with Original Document Attached"
The URL link itself is dynamic and looks something like this (example): http://www.example.net/asp/showattachment.aspx?BlobID=aso23-gjin42-skgn34-23632
Each such email only contains one such link.
When the link is clicked, it goes to a PDF file in the webrowser. The link is not redirected to a different link.
I'd like this to trigger every time such an email is received. I'd like this to operate in the cloud without any desktop interaction.
Thanks!
I solved this myself.
In the "Compose" section, you need to parse out the URL from the email body using your own code. Below is what I used for my specific usage case. For my specific situation, I knew the URL would always be the same number of characters. If the URL length varies between emails, you'll need a more complex parse.
substring(outputs('Html_to_text')?['body'],add(58,indexof(outputs('Html_to_text')?['body'],'Link to Signed Affidavit')),95)

URL to address a page in a PDF which is in a mail?

I search a way to address a single page in a PDF which is in an email.
Is there an official URL/URI spec which handles this case?
AFAIK there are these steps to get to the page:
address the mail.
address the pdf attachment in the mail (there could be several attachments in the mail)
address page number N in the pdf.
It is not possible to add a link to a specific attachment in an email, however it is possible to link to a specific page in a PDF externally.
To target an HTML link to a specific page in a PDF file, add #page=[page number] to the end of the link's URL.
If you host the PDFs somewhere instead of sending them as attachments you can get something close to what you want.

Creating image data URI with proper format

I am sending html emails in php.I want to embed images so that images can be viewed directly
i used base64 encoding but it is not working as gmail is not supporting it.
But i received one email and it has image url in this format:
?ui=2&ik=f9790f3715&view=att&th=146e7afa75b55a47&attid=0.2&disp=emb&realattid=10bf591ea0437383_0.1&zw&atsh=1
and it was displayed directly. how is this working? any help please
These are embedded images. You send an image as an attachment and then use it in your img element like: <img src="cid:yourimage.png">. Gmail transforms the "cid" link to its internal file storage link and that's why it gives <img src="?ui=2&ik=..."> element.
This is one of two common ways to have images within email.
The other way is to keep images in your hosting and send img elements with external links: <img src="http://yourdomain.com/yourimage.png">
I strongly recommend to use the second approach especially if you expect to have a lot of images in your email. I had problems with attached images display on Gmail which I couldn't solve.

Get Content-ID of attached image when composing a new email in iOS

I'm using the MFMailComposeViewController in iOS to create a new dynamic email but have run into an issue when trying to use inline images.
I first tried adding the image as a base64 encoded string, i.e.
<img src="data:image/png;base64, blahblahblah" />
But I can only view that on the iPad while Outlook/Entourage ignore it even though I can see it in the source!
So now I'm trying to add the image as an attachment and link to it via it's content ID, i.e.
<img src="cid:BF6E8B41-4D74-419E-B55E-8F18A07381AE" id="BF6E8B41-4D74-419E-B55E-8F18A07381AE" width="509" height="220">
But have no clue how to get the cid through code!
When I attach an image using AddAttachmentData, the image goes to the bottom and actually generates an <img /> tag with the cid!
Additionally, this ID seems to change with every new email. The one above was my first try, then I sent another one and the Content-ID changed to
<img src="cid:59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" id="59EBFDED-2A31-4787-BF67-9D9ED0FF2B39" width="509" height="220">
The reason I have to do this is because this is a dynamically generated image and it needs to sit inside an email template.
EDIT
I'm beginning to think that this isn't possible. I've been researching for hours now and it looks like iOS won't let you attach an image and link to it via its CID. Thanks Apple -_-
I've hit the same limitation of MFMailComposeViewController. It exposes no way to get content id (cid) of an email attachment, so there is no way to compose an html email message that references the attachment via img src='cid:...'. Since most email clients ignore data urls (inline base 64 encoded images), the best option for composing an html email message with images from an iOS app is to host the images on the web and reference them as img src='http://...'. Most email clients will ask the user for permission to download the images, so this is not ideal, but it's apparently the only option in iOS using public APIs.

Email an image via custom url scheme

I am using custom url schemes. I can send string messages as parameters to my custom url and emailing this to any person. When any person opens this email attachment in device in it open my app installed in device with the passed parameters in my custom url.
Similarly how to email an image via custom url and when any person opens this attachment the image is passed to my app in device.
I tried to encode the image in base64 format and tried to append to my url,but not working.
Any ideas??
Thanks in advance
While there technically isn't a limit placed on url length by the standards, in practice, there is (see these two questions here on SO).
My guess is that you're running into that limit.