tags:

views:

40

answers:

3

Hi. I want to send emails with attachments from my iphone application with custom UI. What can i use for this?

UPD: maybe it's possible to use some smtp library for this task? What can you advice?

A: 

You will need to compile in your own SMTP server, there are a few online that work. This is a pile of hurt. Just use the iPhones Message Composer which is standard. Unless you are building a email spam client this wont really work.

John Ballinger
A: 

you need to do the following first add a framework by right clicking on project. Add -> Existing Framework -> library/frameworks/MessageUI.framework

then in ViewController.h file

import

@interface ViewController : UIViewController { //....yor variables }

in ViewController.m file

  • (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"Sample Email Application"; // title of navigation bar

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }

-(void) composeMail: (id) sender{ MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init]; picker.mailComposeDelegate = self;

[[picker navigationBar] setTintColor:[UIColor blackColor]];


[picker setSubject:@"Sample Email Application"];
[picker setMessageBody:[NSString stringWithFormat:@"Visit for more help %@. ",@"http://google.com"] isHTML:YES];

[self presentModalViewController:picker animated:YES];
[picker release];

}

  • (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [controller dismissModalViewControllerAnimated:YES]; }
Himanshu A Jadav
You missed a crucial point of the original question: `custom UI` ..Apple doesn't want you to modify the UI for `MFMailComposer` and you'd likely get rejected for trying to do so. They don't even like you to change the tint of the nav bar when the modal view shows.
iWasRobbed
i can fill MFMailComposer with data from my custom UI, thanks (:
Division
A: 

The open source three20 framework has designed it's own Mail capabilities via TTMessageController which mimics the original Mail app..You can use that as a starting point and then simply modify the UI of it to your needs.

E-mailing attachments is another story though...

More information: http://www.three20.info/overview

iWasRobbed