Display local image in iPhone HTML mail

后端 未结 5 2158
谎友^
谎友^ 2020-12-17 05:07

In my app, I am composing an HMTL email message with the 3.0+ MFMailComposeViewController. To do this, I created an HTML file, with some placeholders. In my cod

5条回答
  •  無奈伤痛
    2020-12-17 05:45

    Note that using data: URIs won't work across all mail clients. Those that use IE as a rendering engine don't support it at all unless IE8 is installed, and even then, according to Wikipedia, data: URIs are limited to 32 KB maximum.

    The very simplest way to get this to work is to put the image on your own server somewhere, and reference it using a full http:// URI. If you can't do that for some reason (maybe the image is generated as part of using your app), then you can try attaching the image as a MIME sub-part and referencing it from the HTML.

    My mail client doesn't load remote images automatically, but some spam still has images when I open it. This is how it works:

    Attach an image to your mail as suggested by yonel. Somehow you need to also add a Content-ID: header to the sub-part. The contents of this header are then used as the src attribute on your image. My spam message looks like this in the HTML:

    
    

    The attachment sub-part looks like:

    Content-Type: image/jpeg;
        name="image001.jpg"
    Content-Transfer-Encoding: base64
    Content-ID: 
    

    Looking at the documentation for addAttachmentData:mimeType:fileName:, my guess is that you won't be able to get this to work and will have to consider sending the email using raw SMTP.

提交回复
热议问题