';从';参数不支持c++;libcurl mailgun api错误400 我试图用C++ LIbCURL发送邮件枪API的电子邮件。api返回错误消息“'from'参数不是有效地址。请检查文档”
代码';从';参数不支持c++;libcurl mailgun api错误400 我试图用C++ LIbCURL发送邮件枪API的电子邮件。api返回错误消息“'from'参数不是有效地址。请检查文档”,c++,email,libcurl,mailgun,C++,Email,Libcurl,Mailgun,代码 CURL* curl; CURLcode res; std::string readBuffer; std::string user = "api:" + (std::string)"MY_API_KEY"; std::string data = "from='Bob Marley <bob@host.com>'&to='MY_EMAIL@gmail.com'&subjec
CURL* curl;
CURLcode res;
std::string readBuffer;
std::string user = "api:" + (std::string)"MY_API_KEY";
std::string data = "from='Bob Marley <bob@host.com>'&to='MY_EMAIL@gmail.com'&subject='Hello'&text='hi'";
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.mailgun.net/v3/MY_SANDBOX_URL.mailgun.org/messages");
curl_easy_setopt(curl, CURLOPT_USERPWD, user.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
std::cout << readBuffer << std::endl;
}
return 0;
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
-F to=YOU@YOUR_DOMAIN_NAME \
-F to=bar@example.com \
-F subject='Hello' \
-F text='Testing some Mailgun awesomeness!'
输出
* Trying 44.241.76.64:443...
* Connected to api.mailgun.net (44.241.76.64) port 443 (#0)
* Server auth using Basic with user 'api'
> POST /v3/sandbox7847fafcfb12470f8e94e86efad974b4.mailgun.org/messages HTTP/1.1
Host: api.mailgun.net
Authorization: Basic YXBpOmYyMmUxZWEyODgzMTc1YjliYTNmMWMzYTY1Y2JlMTM5LTQ4NzlmZjI3LWEyZjM5MDYw
Accept: */*
Content-Length: 89
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 89 out of 89 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 BAD REQUEST //Error 400 is thrown
< Access-Control-Allow-Headers: Content-Type, x-requested-with, Authorization
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Max-Age: 600
< Cache-Control: no-store
< Content-Type: application/json
< Date: Tue, 15 Dec 2020 20:17:46 GMT
< Server: nginx
< Content-Length: 86
< Connection: keep-alive
<
* Connection #0 to host api.mailgun.net left intact
{
"message": "'from' parameter is not a valid address. please check documentation"
}
*正在尝试44.241.76.64:443。。。
*已连接到api.mailgun.net(44.241.76.64)端口443(#0)
*使用Basic和用户“api”进行服务器身份验证
>POST/v3/sandbox7847fafcfb12470f8e94e86efad974b4.mailgun.org/messages HTTP/1.1
主机:api.mailgun.net
授权:基本YXBPOMYMMUXZWEYODGZMTC1YJLIYTNMMWMZYTY1Y2JLMTM5LTQ4NZLMZJI3LWEYZJM5MDYW
接受:*/*
内容长度:89
内容类型:application/x-www-form-urlencoded
*上传已完全发送:89个字节中的89个
*将捆绑包标记为不支持多用途
输出中抛出错误400
文档示例
CURL* curl;
CURLcode res;
std::string readBuffer;
std::string user = "api:" + (std::string)"MY_API_KEY";
std::string data = "from='Bob Marley <bob@host.com>'&to='MY_EMAIL@gmail.com'&subject='Hello'&text='hi'";
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.mailgun.net/v3/MY_SANDBOX_URL.mailgun.org/messages");
curl_easy_setopt(curl, CURLOPT_USERPWD, user.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
std::cout << readBuffer << std::endl;
}
return 0;
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
-F to=YOU@YOUR_DOMAIN_NAME \
-F to=bar@example.com \
-F subject='Hello' \
-F text='Testing some Mailgun awesomeness!'
curl-s——用户的api:您的api密钥'\
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F来自“兴奋用户”\
-F至=YOU@YOUR_DOMAIN_NAME \
-F至=bar@example.com \
-F主题为“你好”\
-F text='测试邮枪的威力!'
您不需要在发件人地址周围加引号,并且必须对lt/gt符号进行编码:
"from='Bob Marley <bob@host.com>'&to='MY_EMAIL@gmail.com'&subject='Hello'&text='hi'";
你查阅过文档吗?@Chipster是的,我没有发现任何东西。你有没有试过在
from
中只使用一封电子邮件?还有,为什么你在bob marley周围有双引号?在from字段中有一个真实的电子邮件地址呢?我用你的百分比编码技巧得到了它,但是我认为你有一个打字错误<代码>%3D应该是%3E
生成完整字符串“from=Bob Marley%3Cbob@host.com%3E&to&MY_EMAIL@gmail.com“&subject='Hello'&text='hi'”你说得对,这是个打字错误。谢谢你的澄清,我编辑了我的答案,所以现在它是正确的。