如何从iphone应用程序发送邮件?

如何从iphone应用程序发送邮件?,iphone,objective-c,mfmailcomposeviewcontroller,Iphone,Objective C,Mfmailcomposeviewcontroller,我正在尝试从我的应用程序发送邮件。我想输入(动态)收件人id、ccid、sub和消息 谢谢 iOS 3上的Senthilkumar+ 导入#在视图控制器标题中导入 然后: -(无效)showMailPanel{ MFMailComposeViewController*mailComposeViewController=[[MFMailComposeViewController alloc]init]; //仅在iOS

我正在尝试从我的应用程序发送邮件。我想输入(动态)收件人id、ccid、sub和消息

谢谢

iOS 3上的Senthilkumar+ 导入#在视图控制器标题中导入

然后:

-(无效)showMailPanel{
MFMailComposeViewController*mailComposeViewController=[[MFMailComposeViewController alloc]init];
//仅在iOS<3上
//如果([MFMailComposeViewController canSendMail]==否)
//[self-launchMailApp];//您需要
mailComposeViewController.mailComposeDelegate=self;
[mailComposeViewController setToRecipients:[NSArray arrayWithObjects:@“电子邮件地址1”,“电子邮件地址2”,无];
[mailComposeViewController设置主题:@“您的主题”];
[mailComposeViewController setMessageBody:@“您的身体”isHTML:是];
mailComposeViewController.delegate=self;
[self.navigationController presentModalViewController:mailComposeViewController动画:是];
[mailComposeViewController发布];
}
-(void)mailComposeController:(MFMailComposeViewController*)控制器未完成结果:(MFMailComposeResult)结果错误:(NSError*)错误
{   
//通知用户与接口相关的错误
开关(结果)
{
案例MFMailComposer结果已取消:
NSLog(@“结果:已取消”);
打破
案例MFMailComposer结果已保存:
NSLog(@“结果:已保存”);
打破
案例MFMailComposer结果已发送:
NSLog(@“结果:已发送”);
打破
案例MFMailComposer结果失败:
NSLog(@“结果:失败”);
打破
违约:
NSLog(@“结果:未发送”);
打破
}
[controller dismissModalViewControllerAnimated:是];
}
-(无效)启动MailApp{
{
NSString*收件人=@“目的地电子邮件”;
NSString*电子邮件=[NSString stringWithFormat:@“%@%@”,收件人,主题];
email=[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:email]];
}
在iOS 3上+ 导入#在视图控制器标题中导入

然后:

-(无效)showMailPanel{
MFMailComposeViewController*mailComposeViewController=[[MFMailComposeViewController alloc]init];
//仅在iOS<3上
//如果([MFMailComposeViewController canSendMail]==否)
//[self-launchMailApp];//您需要
mailComposeViewController.mailComposeDelegate=self;
[mailComposeViewController setToRecipients:[NSArray arrayWithObjects:@“电子邮件地址1”,“电子邮件地址2”,无];
[mailComposeViewController设置主题:@“您的主题”];
[mailComposeViewController setMessageBody:@“您的身体”isHTML:是];
mailComposeViewController.delegate=self;
[self.navigationController presentModalViewController:mailComposeViewController动画:是];
[mailComposeViewController发布];
}
-(void)mailComposeController:(MFMailComposeViewController*)控制器未完成结果:(MFMailComposeResult)结果错误:(NSError*)错误
{   
//通知用户与接口相关的错误
开关(结果)
{
案例MFMailComposer结果已取消:
NSLog(@“结果:已取消”);
打破
案例MFMailComposer结果已保存:
NSLog(@“结果:已保存”);
打破
案例MFMailComposer结果已发送:
NSLog(@“结果:已发送”);
打破
案例MFMailComposer结果失败:
NSLog(@“结果:失败”);
打破
违约:
NSLog(@“结果:未发送”);
打破
}
[controller dismissModalViewControllerAnimated:是];
}
-(无效)启动MailApp{
{
NSString*收件人=@“目的地电子邮件”;
NSString*电子邮件=[NSString stringWithFormat:@“%@%@”,收件人,主题];
email=[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:email]];
}

您需要这样的东西:

//Import this in your .h file
#import <MessageUI/MessageUI.h>
此外,父视图控制器(代理)需要符合MFMAILCOMPOSEVIEWCONTROLLERGATE协议:

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        //Extra implementation here...
        [self dismissModalViewControllerAnimated:YES];
    }

你需要这样的东西:

//Import this in your .h file
#import <MessageUI/MessageUI.h>
此外,父视图控制器(代理)需要符合MFMAILCOMPOSEVIEWCONTROLLERGATE协议:

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        //Extra implementation here...
        [self dismissModalViewControllerAnimated:YES];
    }

这用于仅发送静态邮件id。但我需要动态发送。例如,当应用程序运行时,我可以键入邮件id主题和邮件内容,然后我想要发送。这用于仅发送静态邮件id。但我需要动态发送。例如,当应用程序运行时,我可以键入邮件id主题和邮件内容,然后我想要发送send.this用于仅发送静态邮件id。但我需要动态发送。例如,当应用程序运行时,我可以键入邮件id主题和邮件内容,然后我想发送。this用于仅发送静态邮件id。但我需要动态发送。例如,当应用程序运行时,我可以键入邮件id主题和邮件内容,然后我想发送我不想发送。