我们正在尝试开发一个邮件iOS应用程序,我已经集成了google gmail-api,也从我的收件箱中提取了邮件。
我通过
发送邮件+ (id)queryForUsersMessagesSendWithUploadParameters:(GTLUploadParameters *)uploadParametersOrNil;
我们如何使用GTLUploadParameters发送邮件?
答案 0 :(得分:0)
- (void)sendEmail:(WLGmailMessage *)message completionBlock:(void (^)(NSError *))completionBlock
{
GTLGmailMessage *gtlGmailMessage = [[GTLGmailMessage alloc] init];
gtlGmailMessage.raw = message.rawString;
// upload parameter
// GTLUploadParameters *upParam = [GTLUploadParameters uploadParametersWithData:GTLDecodeWebSafeBase64(messageRawStr) MIMEType:@"message/rfc822"];
// query
GTLQueryGmail *query = [GTLQueryGmail queryForUsersMessagesSendWithUploadParameters:nil];
query.message = gtlGmailMessage;
[_service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (error) {
NSLog(@"ERROR: %@", error);
} else {
NSLog(@"SENT EMAIL");
}
completionBlock(error);
}];
}
- (NSString *)rawString
{
NSMutableString *message = [NSMutableString new];
[message appendFormat:@"From: %@\n", [_fromAddress rawString]];
[message appendFormat:@"To: %@\n", [_toAddress rawString]];
[message appendFormat:@"Subject: %@\n", _subject];
[message appendFormat:@"Date: %@\n", [self _formattedDate]];
#warning input real ID
[message appendString:@"Message-ID: <tmpID>\n"];
[message appendString:@"\n"];
[message appendString:_body];
return GTLEncodeWebSafeBase64([message dataUsingEncoding:NSUTF8StringEncoding]);
}
- (NSString *)rawString
{
return [NSString stringWithFormat:@"%@ <%@>", _name, _emailAddress];
}
完成项目here