【问题标题】:How to work with Email in iOS app?如何在 iOS 应用中使用电子邮件?
【发布时间】:2011-07-27 15:57:54
【问题描述】:

请告诉我如何发送电子邮件?

这意味着当用户点击我想从应用程序中检索一些数据并将其发送到技术助理的邮件 ID 时,我有一个 uibutton。有什么简单的方法可以做到这一点吗?

【问题讨论】:

  • 请停止使用 xcode 标记您的问题,因为您正在使用此 IDE 来创建您的应用程序。 Xcode 标签应该用于有关 Xcode 的问题。

标签: iphone email


【解决方案1】:

您必须使用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];
}

【讨论】:

  • dismissModalViewControllerAnimated - 被贬低请使用 [self dismissViewControllerAnimated:NO completion:nil];
【解决方案2】:

我使用简单的方法编写电子邮件并使用邮件应用程序打开它。这也可以作为确认;如果用户不想发送它,他可以取消。因此,无需添加“您确定吗?”弹出窗口。他还可以添加注释等。

    NSString *mailurl=[NSString stringWithFormat:
@"mailto:%@?subject=%@%@&body=%@%@",mailaddr,mailsubject,
recipientname,mailmessage,mailsignature];

    [[UIApplication sharedApplication] openURL:
[NSURL URLwithString:[mailurl stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]]];

它很有魅力,我在几个应用程序中使用了这种方法:)

【讨论】:

    【解决方案3】:

    无需创建 UIButton。您必须使用 MFMailComposeViewController 类和 MFMailComposeViewControllerDelegate 协议来发送邮件..

    为了方便您创建电子邮件应用程序,您可以参考以下链接。

    http://mobileorchard.com/new-in-iphone-30-tutorial-series-part-2-in-app-email-messageui/

    它可能对您创建应用程序有所帮​​助

    【讨论】:

      【解决方案4】:

      如果您想从您的用户电子邮件帐户发送电子邮件,您需要使用MFMailComposeViewController 向用户显示屏幕。未经用户许可,您不能/不应从用户电子邮件帐户发送电子邮件!

      否则,您可以启动与服务器的正常 SMTP 连接并使用您自己的登录详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-19
        • 2010-12-04
        • 1970-01-01
        • 2017-10-15
        • 1970-01-01
        • 2015-09-24
        • 2021-12-05
        • 2014-05-15
        相关资源
        最近更新 更多