6
我有一個IOS應用程序,我想通過Mandrill發送一封電子郵件。我試圖實現這一點,但它不工作,我迷惑了自己。IOS JSON從Mandrill發送郵件
按下按鈕時,從IOS應用程序,我記錄此錯誤消息發送一封電子郵件:
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}
我的代碼是:
NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: [email protected]\nTo: [email protected]\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);
請讓我知道我錯了。 。
感謝我做在內容後錯過了\我還需要在每個\ n之前添加一個\ – Steve