ios-->邮件发送

//
//  CViewController.m
//  EmailSendDemo
//
//  Created by YTS on 13-8-27.
//  Copyright (c) 2013年 demo. All rights reserved.
//

#import "CViewController.h"

@interface CViewController ()

@end

@implementation CViewController
@synthesize btnSend = m_btnSend;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)send:(id)sender
{
    NSLog(@"send");
    NSArray *mail = [NSArray arrayWithObjects:@"chendjb@yonyou.com", @"dkl@dlsk.com", nil];
    NSString *subject = @"subject";
    NSString *content = @"to test content";
    [self toSend:mail subject:subject cc:nil bcc:nil content:content];
}

- (void)toSend:(NSArray *)mail subject:(NSString *)subject cc:(NSArray *)cc bcc:(NSArray *)bcc content:(NSString *)content
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    if (picker == nil)
    {
        // 不支持Emai或是没有设置Emai账号
        return;
    }
    
    picker.mailComposeDelegate = self;
    
    [picker setSubject:subject];
    [picker setToRecipients:mail];
    
    if (cc != nil)
    {
        [picker setCcRecipients:cc];
    }
    if (bcc != nil)
    {
        [picker setBccRecipients:bcc];
    }
    
    [picker setMessageBody:content isHTML:NO];
    [self presentViewController:picker animated:YES completion:nil];
    [picker release];
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
{
    NSLog(@"didFinishWithResult");
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

posted on 2013-08-27 18:38  trako  阅读(164)  评论(0编辑  收藏  举报

导航