美文网首页
MFMailComposeViewController<发

MFMailComposeViewController<发

作者: 酒红色T恤 | 来源:发表于2016-05-30 23:03 被阅读937次

---写在前面---

最近在做发邮件时候,用

//[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"mailto:18506666725@l63.com"]];

这段代码时候有一个问题,就是:在给163邮箱发送的时候不会成功,于是就想换一种方式:如题目,下面会贴代码。

步骤:

1. + canSendMail: 判断该设备是否支持发送邮件

2. 创建MFMailComposeViewController 对象

3.为创建的对象设置

1>(收件人) toRecipients:

2>(抄送/密送)bccRecipients:

3>(主题)subject

4>(内容)setMessageBody:isHTML: 

5>(附件)addAttachmentData:mineType:fileName:

4.为MFMailComposeViewController 设置MFMailComposeViewControllerDelegate,--必须实现的代理方法--- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error


代码:

#import"ViewController.h"

#import

@interfaceViewController()<MFMailComposeViewControllerDelegate>

@end

@implementationViewController

- (IBAction)sendEmailUseMF:(id)sender {

if([MFMailComposeViewController canSendMail]) {// 判断设备是否支持发送邮件

// 创建对象

MFMailComposeViewController* picker = [[MFMailComposeViewControlleralloc]init];

// 设置代理

picker.mailComposeDelegate=self;

picker.navigationBar.tintColor= [UIColorblackColor];

// 设置收件人

[pickersetToRecipients:[NSArrayarrayWithObject:@"18503096725@163.com"]];

在此为了简便没有设置抄送/密送,方法类似

// 设置主题

[pickersetSubject:@"aini"];

// 设置邮件内容

[pickersetMessageBody:@"bieshuohuawenwo"isHTML:NO];

//显示MFMailComposeViewController控制器,点击发送即可

[selfpresentViewController:pickeranimated:YEScompletion:nil];

//}

}

#pragma mark -MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{

switch(result) {//这里可以采用弹窗或HUD提示用户

caseMFMailComposeResultSent:

NSLog(@"发送成功") ;

break;

caseMFMailComposeResultCancelled:

NSLog(@"取消") ;

break;

caseMFMailComposeResultSaved:

NSLog(@"保存") ;

break;

caseMFMailComposeResultFailed:

NSLog(@"发送失败") ;

break;

default:

break;

}

[self dismissViewControllerAnimated:YES completion:nil];

}

相关文章

  • MFMailComposeViewController<发

    ---写在前面--- 最近在做发邮件时候,用 //[[UIApplicationsharedApplication...

  • 发发发发发发

    灌灌灌灌灌灌灌灌灌灌灌灌灌灌过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过过

  • 发发发

    抛一枚铜钱 冲向沧茫的太空 滚滚而下雪花花的白银 ...

  • 发发发

  • 发发发

    方法

  • 发发发

    发个公告

  • 发发发

    柔柔弱弱

  • 发发发

    的说法就是单机啊佛多少积分等级

  • 发发发

    水电费速速度度速水电费速度发生的 sdfs的 sdf sd 速度 度

  • 发发发

    小弟弟

网友评论

      本文标题:MFMailComposeViewController<发

      本文链接:https://www.haomeiwen.com/subject/xejcdttx.html