-(void)launchMailApp
{
NSMutableString *mailUrl = [[[NSMutableString alloc]init]autorelease];
//添加收件人
NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com"];
[mailUrl appendFormat:@"mailto:%@", [toRecipients componentsJoinedByString:@","]];
//添加抄送
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
[mailUrl appendFormat:@"?cc=%@", [ccRecipients componentsJoinedByString:@","]];
//添加密送
NSArray *bccRecipients = [NSArray arrayWithObjects:@"fourth@example.com", nil];
[mailUrl appendFormat:@"&bcc=%@", [bccRecipients componentsJoinedByString:@","]];
//添加主题
[mailUrl appendString:@"&subject=my email"];
//添加邮件内容
[mailUrl appendString:@"&body=<b>email</b> body!"];
NSString* email = [mailUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
}
// // ViewController.h // MailDemo // // Created by LUOYL on 12-4-4. // Copyright (c) 2012年 http://luoyl.info. All rights reserved. // #import <UIKit/UIKit.h> #import <MessageUI/MFMailComposeViewController.h> @interface ViewController : UIViewController<MFMailComposeViewControllerDelegate> @end
#pragma mark - 在应用内发送邮件
//激活邮件功能
- (void)sendMailInApp
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (!mailClass) {
[self alertWithMessage:@"当前系统版本不支持应用内发送邮件功能,您可以使用mailto方法代替"];
return;
}
if (![mailClass canSendMail]) {
[self alertWithMessage:@"用户没有设置邮件账户"];
return;
}
[self displayMailPicker];
}
//调出邮件发送窗口
- (void)displayMailPicker
{
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
//设置主题
[mailPicker setSubject: @"eMail主题"];
//添加收件人
NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com"];
[mailPicker setToRecipients: toRecipients];
//添加抄送
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
[mailPicker setCcRecipients:ccRecipients];
//添加密送
NSArray *bccRecipients = [NSArray arrayWithObjects:@"fourth@example.com", nil];
[mailPicker setBccRecipients:bccRecipients];
// 添加一张图片
UIImage *addPic = [UIImage imageNamed: @"Icon@2x.png"];
NSData *imageData = UIImagePNGRepresentation(addPic); // png
//关于mimeType:http://www.iana.org/assignments/media-types/index.html
[mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"];
//添加一个pdf附件
NSString *file = [self fullBundlePathFromRelativePath:@"高质量C++编程指南.pdf"];
NSData *pdf = [NSData dataWithContentsOfFile:file];
[mailPicker addAttachmentData: pdf mimeType: @"" fileName: @"高质量C++编程指南.pdf"];
NSString *emailBody = @"<font color='red'>eMail</font> 正文";
[mailPicker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController: mailPicker animated:YES];
[mailPicker release];
}
#pragma mark - 实现 MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
//关闭邮件发送窗口
[self dismissModalViewControllerAnimated:YES];
NSString *msg;
switch (result) {
case MFMailComposeResultCancelled:
msg = @"用户取消编辑邮件";
break;
case MFMailComposeResultSaved:
msg = @"用户成功保存邮件";
break;
case MFMailComposeResultSent:
msg = @"用户点击发送,将邮件放到队列中,还没发送";
break;
case MFMailComposeResultFailed:
msg = @"用户试图保存或者发送邮件失败";
break;
default:
msg = @"";
break;
}
[self alertWithMessage:msg];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有