tags:

views:

161

answers:

2

I am new to iphone app development, i have created my own app, i want to know whether we can setup the email address for our own app or we have to use only the email that was setup in the iphone. If we can please give me an idea of how to do it.

Thanks in Advance Akhil

A: 

Mails sent from within app will only use the default mail account in Settings.

EDIT: Here is a sample sendEmail() method:

-(IBAction) sendEmail{
    if(![MFMailComposeViewController canSendMail]){
        //show info msg to user
        return;
    }
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"Hello"];
    [controller setMessageBody:@"How are you?" isHTML:NO];
    [controller addAttachmentData:UIImageJPEGRepresentation(myImage,0.8) mimeType:@"image/jpeg" fileName:@"fileName.jpg"];
    [self presentModalViewController:controller animated:YES];
    [controller release];
}

You will need the addAttachmentData method for attachments.

You will also need to implement the didFinishWithResult method to discard the MFMail controller

-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult) result error:(NSError *) error{
    [self becomeFirstResponder];
    [self dismissModalViewControllerAnimated:YES];
}

Make sure your the class where you write these methos implements the < MFMailComposeViewControllerDelegate > protocol

Hope this helps!

Mihir Mathuria
Hi Mihir,At present i am using default setting. can u tell me, how can i attach the files that were present in my app to the mail.Thanks Akhil.
Akhil
Thank u for the help Mihir, it was very helpful.
Akhil
And I still have a downvote (-1) :( . If was helpful you should atleast upvote it or probably accept the answer ;-)
Mihir Mathuria
Sorry, for that. I forgot to accept the answer, i will up vote it.
Akhil
Hi Mihir,I am using the MFMailComposeViewController, its working good if the file is less than 15MB, but if the file is more than 15MB its not even getting attached to the mail. What to do for the files more than 15MB. Is there any other way to do for it.Thanks in Advance.
Akhil
15MB is quite a bit of data and I am not surprised Apple has put up this limit on a resource constrained device like iPhone.1. Dunno how your application is designed but one option is to split the file into smaller chunks and send multiple emails. 2. Or you can try zipping it up before attaching3. Or, if possible, you can transfer the attachment to some webserver and email the link to the usersPost this as a separate question so even others are able to provide their input
Mihir Mathuria
A: 

You could use the SKPSMTPMessage framework for this. I've used it a few times, and it works OK. I would recommend using apple's method though

Matt S.
Thanks Matt i will try it.
Akhil