I stumbled into this same problem and the solution was rather convoluted. It is possible to embed an image in an email. The problem is that for some weird reason the base64 encoded image must not contain new lines (super odd! I know). I'm guessing you are using the NSData+Base64 by Matt Gallagher? So was I! This category creates a multi-line base64 string. The code in the category is
- (NSString *)base64EncodedString
{
size_t outputLength;
char *outputBuffer =
NewBase64Encode([self bytes], [self length], true, &outputLength);
NSString *result =
[[NSString alloc]
initWithBytes:outputBuffer
length:outputLength
encoding:NSASCIIStringEncoding];
free(outputBuffer);
return result;
}
By replacing the third parameter of NewBase64Encode to false you will get a single line base64 string and that worked for me. I ended up creating a new function (just not to break anything else!) within the category.
- (NSString *)base64EncodedStringSingleLine
{
size_t outputLength;
char *outputBuffer =
NewBase64Encode([self bytes], [self length], false, &outputLength);
NSString *result =
[[NSString alloc]
initWithBytes:outputBuffer
length:outputLength
encoding:NSASCIIStringEncoding];
free(outputBuffer);
return result;
}
Using this function to encode the UIImage's NSData worked fine. The email clients I have tested so far all show the embedded image. Hope it works for you!
Edit: As pointed out in the comments, this solution is only partial. The image will be attached as a Data URI in the email. However, not all email clients will display the embedded image.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…