Image attachment is not working properly with emai

2019-07-24 03:03发布

问题:

I am using Mandrill API to send email. Everything is working fine even image attachment is working good. But the problem with image is that email don't have attachment sign in subject line and also attached image don't have a name. The problem is with name key here is image attachment part of JSON. I tried many ways to give name but none of them works for me.

images:[
        {
            "type": "image/png",
            "name": "IMAGECID",
            "content": "ZXhhbXBsZSBmaWxl"
        }
    ]

回答1:

The attachment icon is going to be somewhat specific to the email program you're using. However, in general, if you want something added as an attachment, you should use the attachments array instead of the images array. The images array is for embedding inline images in your HTML content, not simply adding images as attachments. When you use the images array, you need to also include the image identifier in your HTML. So int he case of the same image you've included in the example, your HTML content would need to include this:

<img src="cid:IMAGECID">

This is documented for the images array for the messages/send API endpoint here: https://mandrillapp.com/api/docs/messages.JSON.html#method=send

If you're using Gmail, and want the attachment icon, then put your images in the attachments array instead. They won't render inline in your content, but will be added as attachments.