views:

753

answers:

3

Hi, I want to use MFMailComposeViewController in my app, like in Apple's MailComposer example application, but ...

I don't want the user to be able to edit the "To:" field, in fact I don't want to display it at all. I don't want to display or have the user edit the CC or BCC fields, or even the Subject field. I don't want that "+" button that lets the user open his Contacts page to add recipients.

What I really want is to be able to populate the picker properties (Subject, toRecipients, AttachmentData) programmatically, and programmatically call the "Send" button, so the email gets sent without even showing the UI.

Is there a way to do that? MFMailComposeViewController is the only way I know to send email with image attachments. If MFMailComposeViewController can't be used like that, does anyone know how to send email with attachments in another way?

And finally, if I'm stuck using MFMailComposeViewController, how do you dismiss the keyboard without pressing the Send or Cancel button?!

Thanks for any help. /Steve

A: 

Steve (belatedly): There's no way to set up the controller like you want right now. The philosophy seems to be that the user should always get final say on what the outbound mail looks like, so the user can always edit all of those fields after you prepopulate them.

I don't think there's any other way to send email directly from the iPhone, without having a server component to your application that you can relay the data to for outbound mail spooling. The same thing with the mail philosophy applies-- if the SDK allowed you to just queue outbound mail without the user controlling it, an app could secretly be a spam cannon without the user knowing it.

quixoto
A: 

Hi, I am having a similar issue.Can I dismiss the keyboard at least? If the user rotates the divice, I am loading a separate controller without "send" or "cancel" being pressed. Is there an way to dismiss the keyboard without done or send being pressed? Thanks in advanced guys and gals. I appreciate your help.

Yuri
A: 

Just don't call presentModalViewController:animated after you call alloc init. Then you will need to get the instance of the button on the navigation bar and invoke its click method by simulating a touch event.

I'm pretty sure Apple would reject this app though.

i.e. MFMailComposeViewController *mvc = [[MFMailComposeViewController alloc] init];

.. code to populate the fields.

// DON'T CALL // [self presentModalViewController:mvc animated:YES];

// CODE TO SIMULATE THE TOUCH EVENT (Google For Examples)

[mvc release];

James Wheeler