Gmail API: How to Send Attachments to The Drafts on Swift

How send Email using Gmail api in swift

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: <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))
}

Get attachments in GMail API

The problem is in the base64 encoding: as the documentation say the payload (either in "full" or "raw" mode) is in base64URL encoding, not base64.
So this code is working:

attach, _ := srv.Users.Messages.Attachments.Get(user, messageid, attachmentid).Do()
decoded, err := base64.URLEncoding.DecodeString(attach.Data)
fileout, err := os.OpenFile(...

That said, I saw the full mode (default) is easier to handle
:)

Can't send attachments from draft (Mail.app)

From my research, Mail.app's AppleScript/ScriptingBridge API is pretty much broken when it comes to reading messages and getting its contents.

Swiftmailer config : send mail using gmail

Looks like your live server is missing OpenSSL, so you need to enable it in order to get secure connections working (i.e. enable the php_openssl module). Also check this question.



Related Topics



Leave a reply



Submit