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

调用系统邮件 配置邮件内容 发送邮件

2018年01月08日 ⁄ 综合 ⁄ 共 2167字 ⁄ 字号 评论关闭

库:

MessageUI.framework

头文件:

MessageUI/MFMailComposeViewController.h

具体代码:

    

    MFMailComposeViewController* mail = [[MFMailComposeViewController
alloc]
init];

    mail.mailComposeDelegate =
self;

    

    NSArray *toAdd = [NSArray
arrayWithObject:@"xxxx@163.com"];

    NSArray* ccAdd = [NSArray
arrayWithObject:@"xxxx@163.com"];

    

    [mail setToRecipients:toAdd];

    [mail setCcRecipients:ccAdd];

    [mail setSubject:@"意见反馈", ];

    [mail setMessageBody:@"请将您对我公司软件的使用状况填写在下方,谢谢反馈!" isHTML:NO];

     if (mail) [self
presentModalViewController:mail animated:YES];

//代理方法

-  (void)mailComposeController:(MFMailComposeViewController*)controller

           didFinishWithResult:(MFMailComposeResult)result

                         error:(NSError*)error

{       

    

    switch (result)   

    {  

        case
MFMailComposeResultCancelled:  

        {

            UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:NSLocalizedString(@"邮件发送取消",
nil)

                                                           
message
:@""

                                                          
delegate
:self

                                                  cancelButtonTitle:@"OK"

                                                  otherButtonTitles:nil];

            [alert show];

        }

            break;  

        case
MFMailComposeResultSaved

        {

            UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:
NSLocalizedString(@"邮件保存成功",
nil)

                                                           
message
:@""

                                                          
delegate
:self

                                                  cancelButtonTitle:@"OK"

                                                  otherButtonTitles:nil];

            [alert show];

        }

            break;  

        case
MFMailComposeResultSent

        {

            UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:NSLocalizedString(@"邮件发送成功",
nil)

                                                           
message
:@""

                                                          
delegate
:self

                                                  cancelButtonTitle:@"OK"

                                                  otherButtonTitles:nil];

            [alert show];

        }

            break;  

        case
MFMailComposeResultFailed

        {

            UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:NSLocalizedString(@"邮件发送失败",
nil)

                                                           
message
:@""

                                                          
delegate
:self

                                                  cancelButtonTitle:@"OK"

                                                  otherButtonTitles:nil];

            [alert show]; 

        }

            break;  

        default:  

            break;  

    }  

     [self
dismissModalViewControllerAnimated:YES];

    

}

【上篇】
【下篇】

抱歉!评论已关闭.