send email from swift osx application

后端 未结 3 2128
广开言路
广开言路 2021-02-13 15:45

I am facing problem on sending mail from my osx swift application. To send mail i used the below code

import Foundation
import Cocoa


class sendemail : NSObject         


        
3条回答
  •  逝去的感伤
    2021-02-13 16:13

    Swift 4.2:

    class SendEmail: NSObject {
        static func send() {
            let service = NSSharingService(named: NSSharingService.Name.composeEmail)!
            service.recipients = ["email@yourEmail.eu"]
            service.subject = "Email Subject"
    
            service.perform(withItems: ["Email Content"])
        }
    }
    

    Usage: SendEmail.send()

提交回复
热议问题