gpt4 book ai didi

IOS JSON 从 Mandrill 发送电子邮件

转载 作者:可可西里 更新时间:2023-11-01 03:54:07 25 4
gpt4 key购买 nike

我有一个 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);

请让我知道哪里出错了。

最佳答案

看起来你忘记了“content.”后面的\"。

尝试按如下方式编写“post”变量:

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

希望对你有帮助。

关于IOS JSON 从 Mandrill 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24725183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com