繁体   English   中英

IOS JSON从Mandrill发送电子邮件

[英]IOS JSON sending an email from Mandrill

我有一个IOS应用程序,我想通过Mandrill发送电子邮件。 我试图实现这一点,但它不起作用,我混淆了自己。

当按下按钮从IOS应用程序发送电子邮件时,我记录此错误消息:

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}

我的代码是:

    NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: me@mydomain.com\nTo: me@myotherdomain.com\nSubject: Some Subject\n\nSome content.}"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://mandrillapp.com/api/1.0/messages/send-raw.json"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
    NSLog(@"Post: %@", post);

NSURLResponse *response;
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding: NSASCIIStringEncoding];
NSLog(@"Reply: %@", theReply);

请让我知道我哪里出错了。

它看起来你忘记了“后”的内容。“

尝试编写“post”变量,如下所示:

NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: me@mydomain.com\nTo: me@myotherdomain.com\nSubject: Some Subject\n\nSome content.\"}"];

我希望它有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM