现在的位置: 首页 > 综合 > 正文

开源SMTP协议实现 skpsmtpmessage

2013年09月07日 ⁄ 综合 ⁄ 共 1624字 ⁄ 字号 评论关闭

源码地址:

googlecode      http://code.google.com/p/skpsmtpmessage/

svn checkout http://skpsmtpmessage.googlecode.com/svn/trunk/ skpsmtpmessage-read-only

github:

git clone https://github.com/kailoa/iphone-smtp.git

skpsmtpmessage 是由Skorpiostech,
Inc.
为我们带来的一个SMTP协议的开源实现,使用Objective-c 实现,iOS系统的项目可以直接调用 =]

skpsmtpmessage能够实现不使用iOS系统提供的发送email的两种方法,发送email的功能。

iOS系统框架提供的两种发送Email的方法

使用openURL来实现发邮件的功能:

NSString *url = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

缺点很明显,这样的过程会导致程序暂时退出,即使在iOS 4.x支持多任务的情况下,这样的过程还是会让人觉得不是很方便。这对于开发者而言应该是最简单的实现了,也是在iOS3.0以下唯一的方法来实现发送Email,但是现在也可以使用MFMailComposeViewController来实现发邮件的功能,它在MessageUI.framework中,你需要在项目中加入该框架,并在使用的文件中导入MFMailComposeViewController.h头文件。

#import <MessageUI/MFMailComposeViewController.h>
 
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];

使用该方法实现发送Email是最常规的方法,该方法有相应的MFMailComposeViewControllerDelegate事件:

- (void)mailComposeController:(MFMailComposeViewController*)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error;
{
  if (result == MFMailComposeResultSent) {
    NSLog(@"It's away!");
  }
  [self dismissModalViewControllerAnimated:YES];
}

有一些相关的数据结构的定义在头文件中都有具体的描述:

enum MFMailComposeResult {
MFMailComposeResultCancelled,//用户取消编辑邮件
MFMailComposeResultSaved,//用户成功保存邮件
MFMailComposeResultSent,

抱歉!评论已关闭.