我正在开发一个需要电子邮件访问权限的 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/