问题描述
没有明确的文档,如何做到这一点,我已经尝试使用,但有很多事情在空中。
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.
我已经寻求外部来源。 和源2 。第一个似乎使用api的潜力,使用函数 queryForUsersMessagesSendWithUploadParameters
。
I have sought external sources such. Source 1 and Source 2. The first seems to use the potential of the api, using the function queryForUsersMessagesSendWithUploadParameters
.
虽然第二个是关于再多一点。虽然Objective-C中的这个问题不是一个问题,但GTMMIMEDocument对象不知道在哪里或者是获取或者是一个库。
While the second is about a little more. Although this in Objective-C is not a problem, except for the GTMMIMEDocument object, which do not know where or if it is obtained or a library.
我的问题是有人有点清洁和/或代码更容易理解,或更好的指导发送电子邮件
My question is if someone has a somewhat cleaner and / or code easier to understand, or a better guide in which to send an email
推荐答案
我发现解决方案
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: <mail>\r\n" +
"To: username <mail>\r\n" +
"Subject: Test send email\r\n\r\n" +
"Test body"
println("message \(rawMessage)")
return GTLEncodeWebSafeBase64(rawMessage.dataUsingEncoding(NSUTF8StringEncoding))
}
这篇关于如何使用Gmail api发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!