Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27191

Sending emails from mailComposeViewController when running app on Mac OS leads to issue

I run my iOS app on Mac and all looks good, but when I try to send email it works with some issue.

I figured out that I need to add an account to Mail client but now when I sent emails it goes to some Sent Messages folder instead of Sent folder, and the pdf file I've attaching is completely unreadable from Mail client. On iOS all was good.

@objc func sendInvoice() {
        
        guard let unwrappedPDFData = pdfData,
              let subjectTitle = presenter?.subjectText() else {
            return
        }
        
        if MFMailComposeViewController.canSendMail() {
            let mailComposeViewController = MFMailComposeViewController()
            mailComposeViewController.setPreferredSendingEmailAddress("[email protected]")
            mailComposeViewController.mailComposeDelegate = self
            mailComposeViewController.setSubject(subjectTitle)
            mailComposeViewController.setToRecipients(presenter?.recipients())
            mailComposeViewController.addAttachmentData(unwrappedPDFData, mimeType: "application/pdf", fileName: "Invoice")
            present(mailComposeViewController, animated: true, completion: nil)
        }
    }

Upvotes: 0

Views: 37

Answers (0)

Related Questions