请告诉我如何发送电子邮件?
这意味着当用户点击我需要从应用程序检索一些数据并将其发送给技术助手的邮件ID时,我有一个uibutton ..有没有简单的方法来执行此操作?
答案 0 :(得分:11)
您必须使用MFMailComposeViewController
类和MFMailComposeViewControllerDelegate
协议
PeyloW在他的回答here中提供了以下代码:
首先发送消息:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
然后用户和你一起完成工作 及时获得委托回调:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
答案 1 :(得分:8)
无需创建UIButton。您必须使用MFMailComposeViewController类和MFMailComposeViewControllerDelegate协议发送邮件..
为了方便您创建电子邮件应用,您可以参考以下链接。
http://mobileorchard.com/new-in-iphone-30-tutorial-series-part-2-in-app-email-messageui/
在创建应用时可能对您有所帮助
答案 2 :(得分:2)
如果您要从用户电子邮件帐户发送电子邮件,则需要使用MFMailComposeViewController向用户显示屏幕。未经他们的许可,您不能/不应该从用户电子邮件帐户发送电子邮件!
否则,您可以启动与服务器的正常SMTP连接,并使用您自己的登录详细信息。
答案 3 :(得分:2)
我使用编写电子邮件的简单方法并使用Mail应用程序打开它。这也可以作为确认;如果用户不想发送,他可以取消。所以不需要添加'你确定吗?'弹出。他还可以添加注释等。
NSString *mailurl=[NSString stringWithFormat:
@"mailto:%@?subject=%@%@&body=%@%@",mailaddr,mailsubject,
recipientname,mailmessage,mailsignature];
[[UIApplication sharedApplication] openURL:
[NSURL URLwithString:[mailurl stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]]];
它有魅力,我在几个应用程序中使用此方法:)