I have an iOS app that I would like to send an email through Mandrill. I tried to implement this, but its not working, and I confused myself.
When I click a button to send email from an iOS application, I am logging this error message:
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}
My code is:
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);
Please let me know where I am going wrong.
Steve source share