1

I'm trying to use the postmark api to send an html email that has images in it. I know postmark supports inline image attachments but i don't know how to go about it. I've gone through the documentation but the example given there seems vague and i quite understand it. How do i go about this?

4

1 回答 1

3

Your API call would basically look like this:

    {
    "From": "signature@yourdomain.com",
    "To": "someone@example.com",
    "Subject": "Regular API Test",
    "Tag": "inline",
    "HtmlBody": "<html><body><strong>hello bacon!</strong<br /><img src=\"cid:myimagecid\"/></body></html>",
    "TextBody": "Hello",
    "Attachments": [
        {
            "Name": "bacon.jpg",
            "Content": "/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAQDAwQDAwQEBAQFBQQFBwsHBwYGBw4KCggLEA4RERA...gDgBAA9GT/APrP/9k=",
            "ContentType": "image/jpeg",
            "ContentID": "cid:myimagecid"
        }
    ]
}

You compose your html with references to the image by way of a ContentID (CID) instead of specifying a link to the source. Then, you embed the base64 converted string of your image as the Content part of the attachment. The ContentID field lets the html know where to find the image data in the email.

You can use the framework of whatever platform your using to encode the images as base64. To practice, try a site like http://www.base64-image.de/step-1.php which will give you the base64 string of an uploaded image.

于 2015-01-29T12:46:47.757 回答