In my Catalyst app I use
func setupMailComposer() {
// Check if the device can send email
guard MFMailComposeViewController.canSendMail() else {
print("Mail services are not available")
showMailErrorAlert()
return
}
// Create and configure the mail composer
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.mailComposeDelegate = self
// Set the email details
mailComposeVC.setToRecipients(["example@example.com"])
mailComposeVC.setSubject("Subject for your email")
mailComposeVC.setMessageBody("This is the body of the email.", isHTML: false)
// Attach a file (optional)
if let filePath = Bundle.main.path(forResource: "example", ofType: "pdf"),
let fileData = try? Data(contentsOf: URL(fileURLWithPath: filePath)) {
mailComposeVC.addAttachmentData(fileData, mimeType: "application/pdf", fileName: "example.pdf")
}
// Present the mail composer
self.present(mailComposeVC, animated: true, completion: nil)
}
Since I have updated to macOS 15.1 the canSendMail() function returns false although I have configured Apple Mail (like before in 15.0 where it worked flawlessly).