let group = DispatchGroup()
let message = GTLRGmail_Message()
self.gmailService = GTLRGmailService()
let rawMessage:String = generateRawString() // Raw Message in Base64 String
message.raw = rawMessage
let query: GTLRGmailQuery = GTLRGmailQuery_UsersMessagesSend.query(withObject: message, userId: BSMConstants.BSMGmailAPIUserIdME, uploadParameters: nil)
var gmailMessage: GTLRGmail_Message?
group.enter()
_ = gmailService?.executeQuery(query, completionHandler: { (_, message, error) in
if error == nil && message is GTLRGmail_Message {
gmailMessage = message as? GTLRGmail_Message
}
group.leave()
})
group.wait()
return gmailMessage
Date: Thu, 04 Apr 2019 11:45:06 +0530
From: Mihir Mehta99 <xxx...@xxxxx.xxx>
To: mihir mehta <xxxx...@gmail.com>
Subject: With attachment
Content-Type: multipart/mixed; boundary="dejhLO8fc9OT6X"
--dejhLO8fc9OT6X
Content-Type: multipart/alternative; boundary="CmIHym3S6rVtvf"
--CmIHym3S6rVtvf
Content-Type: text/plain; charset="UTF-8"
PFA
Sent from Blueskyme App
--CmIHym3S6rVtvf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: base64
IAoKCgpQRkE8YnI+PGJyPjxicj4gPGEgaHJlZj0iaHR0cHM6Ly9ibHVlc2t5bWUucGFnZS5saW5rL2FwcHMiPgpTZW50IGZyb20gQmx1ZXNreW1lIEFwcDwvYT4=
--CmIHym3S6rVtvf--
--dejhLO8fc9OT6X
Content-Type: image/png; name="3CDE712B-71F3-436D-9C34-E7100A7987F4.png"
Content-Disposition: attachment; filename="3CDE712B-71F3-436D-9C34-E7100A7987F4.png"
Content-Transfer-Encoding: base64
///////////////////// BASE64 STRING OF ATTACHMENT GOES HERE (SIZE AROUND 9 MB) //////////////////////////////
--dejhLO8fc9OT6X--
{
NSErrorFailingURLKey = "https://www.googleapis.com/gmail/v1/users/me/messages/send?prettyPrint=false";
NSErrorFailingURLStringKey = "https://www.googleapis.com/gmail/v1/users/me/messages/send?prettyPrint=false";
NSLocalizedDescription = "unknown error";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-998 \"(null)\" UserInfo={NSErrorPeerAddressKey=<CFData 0x600002bbcff0 [0x110c19b68]>{length = 16, capacity = 16, bytes = 0x100201bbacd91bca0000000000000000}, _kCFStreamErrorCodeKey=0, _kCFStreamErrorDomainKey=2}";
"_NSURLErrorFailingURLSessionTaskErrorKey" = "LocalDataTask <400B1836-8DDB-43D3-96FB-C110931F71CF>.<1>";
"_NSURLErrorRelatedURLSessionTaskErrorKey" = (
"LocalDataTask <400B1836-8DDB-43D3-96FB-C110931F71CF>.<1>"
);
"_kCFStreamErrorCodeKey" = 0;
"_kCFStreamErrorDomainKey" = 2;
}
It fails immediately<NSHTTPURLResponse: 0x600000da2e20> { URL: https://www.googleapis.com/gmail/v1/users/me/messages/send?prettyPrint=false } { Status Code: 413, Headers {
"Cache-Control" = (
"private, max-age=0"
);
"Content-Encoding" = (
gzip
);
"Content-Length" = (
133
);
"Content-Type" = (
"text/html; charset=UTF-8"
);
Date = (
"Thu, 04 Apr 2019 06:55:24 GMT"
);
Expires = (
"Thu, 04 Apr 2019 06:55:24 GMT"
);
Server = (
GSE
);
"alt-svc" = (
"quic=\":443\"; ma=2592000; v=\"46,44,43,39\""
);
"x-content-type-options" = (
nosniff
);
"x-frame-options" = (
SAMEORIGIN
);
"x-xss-protection" = (
"1; mode=block"
);
} }
- (void)URLSession:(NSURLSession *)session
dataTask:(NSURLSessionDataTask *)dataTask
didReceiveResponse:(NSURLResponse *)response
completionHandler:(void (^)(NSURLSessionResponseDisposition))handler {
}