【问题标题】:Links inside email message body电子邮件正文中的链接
【发布时间】:2012-02-07 16:18:43
【问题描述】:

我需要修改现有项目。在这个项目中,应用程序在多个(许多)地方发送带有预设文本的电子邮件。使用的功能是

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailString]];

这显然会打开 iOS 邮件,准备发送邮件。 现在我需要在邮件正文中包含链接。是否可以在所有这些地方不切换到 MFMailComposeViewController 来做到这一点?怎么样?

【问题讨论】:

    标签: ios xcode email mfmailcomposeviewcontroller openurl


    【解决方案1】:

    这很简单。 每个 html 标记都应附加,在 url 开头和结尾的双引号前使用正斜杠
    示例:

        NSString *bodyText =@"<html>";
        bodyText = [bodyText stringByAppendingString:@"<head>"];
        bodyText = [bodyText stringByAppendingString:@"</head>"];            
        bodyText = [bodyText stringByAppendingString:@"<body>"];
        bodyText = [bodyText stringByAppendingString:@"<a     href=\"http://www.devaski.com\">My blog"];
        bodyText = [bodyText stringByAppendingString:@"</a>"];
        [mailComposer setMessageBody:bodyText isHTML:YES];
    

    【讨论】:

      【解决方案2】:

      看看这份文件 - https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MailLinks.html#//apple_ref/doc/uid/TP40007892-SW1

      简短的回答是,是的,您可以通过在 URL 中添加 body 参数(即 mailto:john@apple.com?body=This%20goes%20to%20body)来预填充消息正文。但请注意,字符串必须正确转义,您可以借助 NSString 的 stringByAddingPercentEscapesUsingEncoding:

      轻松完成

      我假设正文中任何看起来像 URL 的 URL 都会被邮件应用程序本身转换为链接 - 不确定,测试一下。

      【讨论】:

      • 感谢您的回复。确实如此,我的意思是我设法预先填充了正文,并且任何地址(例如 www.mysite.com)都会通过 Mail 转换为链接。我需要实现的是有一个链接,例如“访问我们的网站”。使用 MFMailComposeViewController 我猜你可以通过 html 来完成。
      • 是的,这是您必须使用 HTML 处理的事情,如果答案有帮助,请将其标记为已接受。
      • 这比我想象的要容易,实际上嵌入在 emailString 中的 HTML 可以正常工作。周围发布了一些错误信息,指出 openURL 方式不允许使用 html。还是谢谢你。
      猜你喜欢
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 2022-11-25
      • 2021-05-08
      • 1970-01-01
      • 2019-07-05
      相关资源
      最近更新 更多