开发者

Mail send framework for iphone

I want to send emai开发者_如何学Gols 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?


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 <MessageUI/MessageUI.h>

@interface ViewController : UIViewController  <UITextFieldDelegate, MFMailComposeViewControllerDelegate>{
//....yor variables
}

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];
}


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.


If you want to send email without using the native mail composer UI and without setting up your own SMTP server, you can check out PostageApp (http://postageapp.com/). There's an iOS / Mac API wrapper that lets you send email through the API. https://github.com/postageapp/postageapp-objc

(Disclosure: I work for PostageApp and developed the plugin.)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜