I search solution to send a mail with attachment. I have this code but the file is not attached...
if let url = URL(string: "mailto:\(email)?subject=report&body=see_attachment&attachment=/Users/myname/Desktop/report.txt") {
NSWorkspace.shared().open(url)
}
I have see it maybe work with MessageUI, but I can't import this framework I don't know why. I get this error message : No such module 'MessageUI' I checked in General > Linked Frameworks and Libraries, but there are not MessageUI...
Anyone have a solution to add file in mail? Thanks
It seems that
attachment
inmailto:
URLs are not supported on macOS (not always at least...details seems sketchy dependent on where you look on the internet :))What you can use instead I found out from this blog post, is an instance of
NSSharingService
documented hereHere is an example demonstrating how to use it.
And in your case you could do something like:
Hope that helps you.
First of all you should import
import MessageUI
. For this add framework to the project.Example:
After investigate
MFMailComposeViewControllerDelegate
for knowing when you end sending email.Example of the creating of the email:
Working example is presented by this link.