2014-07-13 2 views
6

Mandrill을 통해 전자 메일을 보내려는 IOS 응용 프로그램이 있습니다. 나는 이것을 구현하려고 시도했지만 작동하지 않고 스스로 혼란스러워했다. IOS JSR이 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); 

알려 주시기 바랍니다. . 그것은 콘텐츠 "후"의 \를 잊어 보이는

답변

5

다음과 포스트 "변수".

시도는 쓰기 ".

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

가 나는 그것이 도움이되기를 바랍니다 내가 한

+0

감사합니다 \ after content를 놓치지 마라. \ 모든 것을 \ 앞에 추가해야한다. \ n – Steve

관련 문제