ios调用系统邮件

1.引入MessageUI.framework框架

2.实例化类MFMailComposeViewController,判断用户的设备是否设置邮箱 if ([mailClass canSendMail])

3.具体代码:

MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];     //创建邮件controller

mailPicker.mailComposeDelegate = self;  //设置邮件代理

[mailPicker setSubject:@"Send WebView ScreenShot"]; //邮件主题

[mailPicker setToRecipients:[NSArray arrayWithObjects:@"lipengxuan48@163.com",

@"lipengxuan48@gmail.com", nil]]; //设置发送给谁,参数是NSarray

//cc

//   [mailPicker setCcRecipients:[NSArray arrayWithObject:@"zhuqil@163.com"]]; //可以添加抄送

//bcc

// [mailPicker setBccRecipients:[NSArray arrayWithObject:@"secret@gmail.com"]];

[mailPicker setMessageBody:@"WebShotScreen n in Attachment!" isHTML:NO];     //邮件主题

NSData *imageData = UIImagePNGRepresentation(viewImage);//这里获取截图存入NSData,用于发送附件

[mailPicker addAttachmentData:imageData mimeType:@"image/png" fileName:@"WebScreenShot"];//发送附件的NSData,类型,附件名

[self presentModalViewController:mailPicker animated:YES];   //把当前controller变为邮件controller

4.实现代理方法

- (void)mailComposeController:(MFMailComposeViewController*)controller

didFinishWithResult:(MFMailComposeResult)result

error:(NSError*)error

{

switch (result){

case MFMailComposeResultCancelled:  NSLog(@”Mail send canceled…”);

break;

case MFMailComposeResultSaved:    NSLog(@”Mail saved…”);

break;

case MFMailComposeResultSent:             NSLog(@”Mail sent…”);

break;

case MFMailComposeResultFailed:  NSLog(@”Mail send errored: %@…”, [error localizedDescription]);

break;

default:             break;

}

[self dismissModalViewControllerAnimated:YES];

}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值