MFMailComposeViewController adds null Content-Id - iphone

This is my first post to the group so please be kind :)
I am sending a couple of audio attachments from my app as follows:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
[picker setSubject:#"Test message"];
NSArray *toRecipients = [NSArray arrayWithObject:#"foo#bar.com"];
[picker setToRecipients:toRecipients];
// multiple attachments are made as follows
NSData *myData = [NSData dataWithContentsOfFile:filePath];
[picker addAttachmentData:myData mimeType:#"audio/x-caf" fileName:fileName];
[picker setMessageBody:#"test message" isHTML:NO];
[controller presentModalViewController:picker animated:YES];
A mailComposeController method takes care of dismissing the modal view.
Unfortunately, when the message is delivered the mime headers for the attachments land up having the Content-Id set to null. Here is what it looks like:
Content-Type: audio/x-caf; name="audio_1.caf"
Content-Transfer-Encoding: base64
Content-Id: <(null)>
Content-Disposition: attachment; filename="audio_1.caf"
If I manually delete the Content-Id field and reload the message in my Mac Mail program (Mail Version 3.6) the attachments show up correctly. In other words, I don't really need/want theContent-Id to be inserted in the mime header.
Also, its worth mentioning that for debugging purposes if I set the mime type to "image/jpeg" the mime header does get a valid Content-Id string. All my attachments show up in Mail. As is to be expected, in that case the attachments don't open correctly on the Mac or iPhone.
Any help would be greatly appreciated.
thanks,
apurva

According to this post, you cannot manually set the Content-ID
How to add a UIImage in MailComposer Sheet of MFMailComposeViewController

OK. Figured it out -- more by accident than anything else.
The null content ids seem to be inserted by the mail server (not my app or MFMailComposeViewController).
Initially I was testing the send with a personal yahoo account. Thats when I ran into the problem. When I switched to my work account the problem disappeared.
thanks,
apurva

Related

Attachments using email uri scheme in iOS

I am implementing an iphone application (iOS 4.2) from where I would like to trigger the email client to send messages with attachments. I could effectively use uri schemes in combination with the class NSURL in order to trigger the email app but I was wondering whether it is possible to attach images. I have tried with mailto:whoever#wherever.org?subject=sthg&body=sthgelse&attachment=/path/to/file but the attachments are not included. I know iphone applications are sandboxed therefore it is possible that the email utility were not able to access the path to my image since it is located in my application bundle. On the other hand I was considering to administer my images with the photo manager. (1) Is there a way to include attachments in this way? (2) If so, is it possible to reference images either from my app or from the photo client? I could not find any attachments argument in the mailto RFC but maybe Apple has provided some way to achieve this.
Thanks in advance for your help,
Luis
MFMailComposeViewController will be able to do that, some example of usage belows:
remember to add MessageUI.framework
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:#"Whatever"];
// Set up recipients
NSArray recipients = [NSArray arrayWithObject:#"whoever#wherever.org"];
[email setToRecipients:recipients];
// Attach an image to the email
UIImage *attachment = ...;
NSData *data = UIImagePNGRepresentation(attachment);
[email addAttachmentData:myData mimeType:#"image/png" fileName:#"ok.png"];
// Fill out the email body text
NSString *emailBody = #"test mail";
[email setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[email release];
Instead of using the mailto: URL scheme, you should use the MFMailComposeViewController which allows you to add attachments. It also has the added benefit that using will not leave your app.
If one does not have account MFMailComposeViewController simply crashes.
Yes, you can call canSendMail first with the result NO(!), what next?
The answer is - use 'mailto:'. It'll popup dialog to create account.

MFMailComposeViewController in iphone app

hii every one
can we use " MFMailComposeViewController " with out using " presentModalViewController" , i mean i need to send email with out navigating to that mail composer page
i did a test project with following code
- (IBAction)buttonPressed {
arrRecipients = [[NSMutableArray alloc]init];
[arrRecipients addObject:#"xxxxxxx#gmail.com"];
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setSubject:#"Ravikiran test mail"];
[mailController setToRecipients:arrRecipients];
[mailController setMessageBody:#"this is my test app" isHTML:YES];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
it is sending mail but it is navigating to mail composer page & then its sending but i need to send mail just on click of the button
No, you cannot use MFMailComposeViewController to send an email without user interaction. There are probably 3rd parties libraries that let you do this, but the iOS SDK does not allow you to.
Also, you're leaking the arrRecipients array.
Best way for your needs is to have a web service which sends the data to an email id.
its always to good to inform the user in some way before sending the mail.
Thanks!

Easy way to open the Mail application with an pre-defined message subject and body?

In my app the user generates text content. I want to enable the user to launch the Mail application, which then should contain a specified subject and message body. Like: You write a poem in my app and then want to send it to your new girlfriend. So you tap a mail icon and the Mail app opens, containing already an subject and message body with your poem inside.
Someone said there is a kind of URL mechanism for that?
You can use MFMailComposeViewController for sending the mail.
-(void)OpenMail{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"my new poem"];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
emailBody is string which contains the poem.
All the best.
Apple URL Scheme Reference: Mail Links lists all your options.
Or you use MFMailComposeViewController.

send an HTML formatted email using MFMailComposeViewController

I am formatting a mail with HTML content and sending it using MFMailComposeViewController.But on the receiver side mail is not reaching in HTML format.Only Plain text is visible.How could I resolve this issue.Thanks in advance.
Be sure to set the message body using the following lines:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *emailBody = #"<p><b>Hello World</b></p>";
[picker setMessageBody:emailBody isHTML:YES];
Even if you set isHTML param to YES, your message body can be sent as plain/text if the message body can be represented as such.
In my case adding a link in the message body helped. Bold formatting with tags works too. Tricky!
Tested on iPod 1G 3.1.3.

MFMailComposeViewController attachment file size limit

I'm using MFMailComposeViewController to send a file. Everything works fine with files under 15mb. Anything over, and the file simply doesn't get attached to the MFMailComposeViewController view. It's not that the email server isn't accepting, its that it never gets attached in the first place.
Does anyone have any ideas if there's a way to resolve that?
I know many email services can't handle attachments over 5 or 10mb, but other services allow you much larger file size.
MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
NSString* path = [NSString stringWithFormat:#"%#/%#/%#", NSHomeDirectory(), #"Documents", fileName];
NSData *data = [NSData dataWithContentsOfMappedFile:path]; //also tried dataWithContentsOfFile with same results
[mail addAttachmentData:data mimeType:#"audio/x-caf" fileName:[NSString stringWithFormat:#"%#.caf", label]];
[appDelegate.tabBarController presentModalViewController:mail animated:YES];
Loading a 15 MB anything into RAM on a pre-2009 iPhone or iPod is going to really push the limits of your process's available memory, so it's not surprising there's a cap. I wouldn't try to convince the compose view to accept a larger attachment; instead, I'd suggest you transfer the file to some external server and either e-mail a link to it or send the mail from there.
Currently it has a 21mb limit (relevant to iOS 15). But I could sent at least 24mb when pressed Try. 25mb couldn't be attached and MFMailComposeViewController was closed by system at all.