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
How to Get Part of a String in Swift
Swift 3: Converting Data to String Returns a Nil Value
Ambiguous Use of Operator '-' in Swift with 'Abs()'
How to Set the iOS13 Uisegmentedcontrol Backgroundcolor to White
Swift Firestore Check If Documents Exists
Using @Discardableresult for Closures in Swift
Left Aligned Horizontal Stackview and Top Aligned Vertical Stackview
Swift - Getting Only Alphanumeric Characters from String
Swift Language Statically or Dynamically Dispatched
Generic Method Override Not Working in Swift
Swift Protocol as Generic Parameter
Gcdasyncsocket Multiple Connections Wont Accept Data from Multiple Sockets
Swiftui Multiline Text Background Color
Distributednotificationcenter - How to Pass Data Between Applications
Swift Vscode Class in Other File Not Recognized
Call Function When If Value in Nsuserdefaults.Standarduserdefaults() Changes