So I am using MFMailComposeViewController
to attach pdf files to an email and send it out using the default iOS mail app set up with an exchange account.
If I send a file with size 4863K it works perfectly. Everything goes off as expected.
If I send a file with size 5688K it seems like its working and gets MFMailComposeResultSent
as the result sent back to the delegate.
However, the mail never arrives and when I look in the mail app, I see that it is stuck in the Outbox with an error of:
The server rejected the message
What's super weird is that when I try to resent the message from the outbox, it sends out perfectly fine and gives no further error message.
I am sort of at my wits end and have not the first clue what could be going wrong. Clearly I cannot screw around with apple's code, but there don't seem to be many options with the MFMailComposeViewController
that I could possibly have screwed up.
The code is fairly straightforward:
- (void) setAttachments:(NSArray*)attatchments
ofDraft:(MFMailComposeViewController*)draft
{
if (attatchments)
{
for (NSString* path in attatchments)
{
NSData* data = [self getDataForAttachmentPath:path];
NSString* basename = [self getBasenameFromAttachmentPath:path];
NSString* pathExt = [basename pathExtension];
NSString* fileName = [basename pathComponents].lastObject;
NSString* mimeType = [self getMimeTypeFromFileExtension:pathExt];
// Couldn't find mimeType, must be some type of binary data
if (mimeType == nil) mimeType = @"application/octet-stream";
[draft addAttachmentData:data mimeType:mimeType fileName:fileName];
}
}
}
The fact that this works for smaller files implies to me that there is nothing wrong with this code and it is copied out of a cordova plugin that sees pretty wide usage. But for whatever reason, files that are over ~5MB just fail for no apparent reason.
Thanks for your help.
Update I captured the http traffic and discovered that in the situation where the mail is sent using the MFMailComposeViewController, the POST request has a content-length of 0, which is not allowed, so the server returns a 400 error. When I try to resend the same message from the mail app directly, the content-length is the size expected.
This appears to be a limitation of the MessageUI framework, but I cannot verify that there is a universal limitation imposed by Apple.