How send Email using Gmail api in swift

前端 未结 4 1871
一个人的身影
一个人的身影 2021-01-03 08:15

The Gmail Api has no clear documentation on how to do this, I have been trying with this but there are many things that are in the air.

I have sought external source

4条回答
  •  被撕碎了的回忆
    2021-01-03 08:54

    I found the solution

    class func sendEmail() {
    
            var gtlMessage = GTLGmailMessage()
            gtlMessage.raw = self.generateRawString()
    
            let appd = UIApplication.sharedApplication().delegate as! AppDelegate
            let query = GTLQueryGmail.queryForUsersMessagesSendWithUploadParameters(nil)
            query.message = gtlMessage
    
            appd.service.executeQuery(query, completionHandler: { (ticket, response, error) -> Void in
                println("ticket \(ticket)")
                println("response \(response)")
                println("error \(error)")
            })
        }
    
        class func generateRawString() -> String {
    
            var dateFormatter:NSDateFormatter = NSDateFormatter()
            dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format
            var todayString:String = dateFormatter.stringFromDate(NSDate())
    
            var rawMessage = "" +
                "Date: \(todayString)\r\n" +
                "From: \r\n" +
                "To: username \r\n" +
                "Subject: Test send email\r\n\r\n" +
                "Test body"
    
            println("message \(rawMessage)")
    
            return GTLEncodeWebSafeBase64(rawMessage.dataUsingEncoding(NSUTF8StringEncoding))
        }
    

提交回复
热议问题