0

I am using mailgun. now i am sending mail from gmail to my domain. using mailgun api i am getting that and showing that content in my webpage. but when i am adding images in middle of the text or in signature of the mail image is not showing in webpage. it is just showing broken image because it is showing like this:

<img width="375" height="134" src="cid:ii_i2davb0f0_1499f1c3646e87a5">

How can i show these images in web page?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
krishna
  • 923
  • 3
  • 15
  • 42

2 Answers2

1

The part after the cid: is the unique identifier for the attachment that has that image. You will need to check the attachment headers, and match the one for that image, and likely de-base64/uudencode the image back to binary, store on your server, and show it using normal means.

Looking at their docs here, http://documentation.mailgun.com/user_manual.html#routes

There will be an attachment-x part of the returned message array, that there is one for each attachment. You will just have to check which one matches your identifier

My bad: they will be in the content-id-map section. Check the "Parsed Messages Parameters" section of the routes link above

Uberfuzzy
  • 8,253
  • 11
  • 42
  • 50
  • he was not asking about attachments :) – Ares Draguna Nov 11 '14 at 16:00
  • Yes, he was. Thats where cid: images come from. They are inline images in emails that get stored in the normal attachment section of the mail body, but with only ident names, and not normal filenames, most clients weed them out and de-ref the images inline as they should. If he's using some sort of api to access the mail data, he has to do all that him self to 'show' them. – Uberfuzzy Nov 11 '14 at 16:11
  • "but when i am adding images in middle of the text or in signature of the mail image is not showing in webpage" I thought he was obviously trying to add an image to the body of the email :-? – Ares Draguna Nov 11 '14 at 16:13
  • From what I can tell, he's using their mail api to read an existing message and display it as a webpage (think mail.google.com) and inline images are not showing – Uberfuzzy Nov 11 '14 at 16:15
  • God have mercy :) maybe he will explain? – Ares Draguna Nov 11 '14 at 16:16
0

I don't know how you create the body of your email, but it has to contain as a src a link to your server stored image like this:

(replace with this line in the file that creates the body of your email)
<img width="375" height="134" src="http://yourdomain.com/path/to/image.format">

and when you will have it in your email, it will get the image from your server.

Hope this helps! :D

Ares Draguna
  • 1,641
  • 2
  • 16
  • 32
  • thanq..i will try as you said. yes i saw your comments. i am asking about inline images which were inserted in mail body those were not displayed in my webpage. – krishna Nov 11 '14 at 18:09
  • can any body please tell me how to parse – krishna Nov 12 '14 at 18:48
  • i am getting json format like this $str="{\"ii_i2ecp4vs0_149a2e5b77d06876\": \"attachment-1\"}"; But how to copy that image into my server – krishna Nov 13 '14 at 10:13
  • you just put it in your server and save in the db the file name. When you need it, you fetch it with a reference to the image id in order to create the image path in the `src` of the `img` tag :) – Ares Draguna Nov 13 '14 at 10:56
  • if you want to save a image to your server you need a whole different PHP script. But the functionality is reversed. You save the image to your server, insert a new line in your images DB and then when you need it, repeat the above procedure – Ares Draguna Nov 13 '14 at 11:00
  • ahhhhhh....i did not get you what you are saying......how to copy image into folder? – krishna Nov 13 '14 at 14:54
  • Physically? Copy-Paste with a mounting IDE like expanDrive or something like this, or using linux commands. Is this your issue? You don't know how to use FTP? – Ares Draguna Nov 13 '14 at 14:56
  • content-id-map ==> {\"\": \"attachment-1\"} this is the attachment. how to get image from this and copy this image into my folder – krishna Nov 14 '14 at 03:43