send email from swift osx application

后端 未结 3 2125
广开言路
广开言路 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:15

    This works for me:

    import Cocoa
    
    class SendEmail: NSObject {
        static func send() {
            let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
            service.recipients = ["abc@dom.com"]
            service.subject = "Vea software"
            
            service.performWithItems(["This is an email for auto testing through code."])
        }
    }
    

    Usage:

    SendEmail.send()
    

提交回复
热议问题