【发布时间】:2015-05-12 00:02:14
【问题描述】:
我正在将 Mailgun 集成到我的 iOS 应用程序中,并尝试发送带有附件的电子邮件。电子邮件已发送,但附件似乎被忽略了。有任何想法吗?代码如下。我正在使用 AFNetworking 2,并且我不使用本机 Mailgun Objective-C SDK,因为它似乎没有得到维护。
NSString *path = [NSString stringWithFormat:@"https://api:%@@api.mailgun.net/v3/%@/messages", kTIXMailgunAPIKey, kTIXMailgunDomain];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[ @"text/plain", @"text/html", @"application/json" ] ];
NSData *attachment = [attachments firstObject];
NSDictionary *parameters = @{
@"from" : fromAddress,
@"to" : toAddress,
@"subject" : @"Inline",
@"text" : @"Email body",
@"content-type" : @"multipart/form-data",
@"attachment" : attachment,
};
[manager POST:path
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Success sending message. Response: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error sending message: %@", error);
}];
我可以使用 curl 发送附件,例如:
curl -s "https://api:key-
[redacted]@api.mailgun.net/v3/sandbox[redacted].mailgun.org/messages" \
-F from=[redacted]@gmail.com \
-F to=[redacted]@gmail.com \
-F subject='Check this out!' \
-F text='LOL' \
-F attachment=@"lolcat.png"
【问题讨论】:
标签: objective-c afnetworking-2 mailgun