2010-07-23 65 views
2

我想用自定義用戶界面從我的iPhone應用程序發送帶有附件的電子郵件。我能爲此使用什麼?郵件發送框架爲iphone

UPD:也許有可能使用一些smtp庫來執行此任務?你可以建議什麼?

回答

2

您需要執行以下操作 首先通過右鍵單擊項目添加框架。 添加 - >現有框架 - > 庫/框架/ MessageUI.framework

然後 在ViewController.h文件

#import <MessageUI/MessageUI.h> 

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

ViewController.m文件

- (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]; 
} 
+1

你錯過了原來的問題的一個關鍵點:'定製UI' ..Apple不希望你來修改'MFMailComposer的UI '而且你很可能因爲試圖這樣做而被拒絕。當模態視圖顯示時,他們甚至不喜歡你改變導航欄的色調。 – iwasrobbed 2010-07-23 14:09:52

+1

我可以使用我的自定義UI中的數據填充MFMailComposer,謝謝(: – Division 2010-08-12 13:33:44

1

你需要在你自己的SMTP服務器上編譯,有幾個在線工作。這是一堆傷害。只需使用標準的iPhone消息編輯器即可。除非你正在建立一個電子郵件垃圾郵件客戶端這不會真的工作。

0

開源three20框架已通過TTMessageController設計它自己的郵件功能,它模仿原來的郵件應用程序。你可以使用臨時t作爲起點,然後簡單地修改它的UI以滿足您的需求。

E-郵件附件是另一回事,但...

的更多信息:http://www.three20.info/overview

1

如果你想發送電子郵件,而無需使用本地郵件撰寫界面,沒有建立自己的SMTP服務器,可以查看PostageApp(http://postageapp.com/)。有一個iOS/Mac API包裝器,可讓您通過API發送電子郵件。 https://github.com/postageapp/postageapp-objc

(披露:我爲PostageApp工作,並開發插件。)