macos - 如何在 Mac 应用程序的 Xcode 上启动电子邮件

标签 macos xcode6

我正在开发一个需要电子邮件访问权限的 Mac 应用

这是我在 ios 上尝试过的代码

-(IBAction)Contact us:(id)sender {
//Email Subject
NSString *emailTitle = @"";
//Email Content
NSString *messageBody = @"";
//Email Address
NSArray *toRecipients =[NSArray arrayWithObject:@"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6900070f06290408070d081b0007440c1a190c0802470a0604" rel="noreferrer noopener nofollow">[email protected]</a>"];

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:YES];
[mc setToRecipients:toRecipients];

}

如何在 Mac 应用程序上打开默认电子邮件客户端

最佳答案

在 MacOS 中,您可以轻松地发送电子邮件,如下所示:

class SendEmail: NSObject {
    static func send() {
        let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
        service.recipients = ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aacbc8c9eacec5c784c9c5c7" rel="noreferrer noopener nofollow">[email protected]</a>"]
        service.subject = "Vea software"

        service.performWithItems(["This is an email for auto testing through code."])
    }
}

用法:

SendEmail.send()

关于macos - 如何在 Mac 应用程序的 Xcode 上启动电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26249090/

相关文章:

ios - "Cannot invoke ' CGPointMake ' with an argument list of type ' ((), CGFloat) '"在 Swift 中收到

ios - cocoa touch 框架 Assets 在应用程序项目中不可见

linux - 如何使用 mac 键盘粘贴到虚拟框中的终端 linux?

macos - 在版本中创建分支(Mac Subversion 客户端)

swift - 如何使用 Swift 检查 macOS 应用程序复选框的状态

c - OS X sockaddr_in6 未声明

macos - 从 shell 脚本或命令行写入 Mac OS X 控制台日志

image - 如何在 Swift 中更改 IBAction UIButton 的图像?

ios - 如何使用 HP SCA 扫描我的 iOS 项目并获取报告

Xcode6 无法将我的项目存档到 ipa