当我尝试卷曲 Azure 的 SendMail 端点时,出现以下错误。该文档并没有真正的帮助。我做错了什么?
endpoint=https://dev.azure.com/myorg/myproject/_apis/wit/sendmail?api-version=7.1-preview.1
body='{
"message": {
"body": "Test Body",
"cc": {},
"to": {
"tfsIds": ["my-tfsIds-id"]
},
"replyTo": {},
"subject": "Test Subject"
}
}'
curl -X POST $endpoint --data "$body" -H "Authorization: Basic $pat" -H "Content-Type: application/json" "Content-Length: ${#body}" -vL
Note: Unnecessary use of -X or --request, POST is already inferred.
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>
PS:我也得到了重定向,我也不明白为什么,但我猜这是登录权限?
* Connection #0 to host dev.azure.com left intact
* Issue another request to this URL: 'https://xxxxx.vssps.visualstudio.com/_signin?realm=dev.azure.com&reply_to=https%3A%2F%2Fdev.azure.com%2FMYORG%2FMYPRODJECT%2F_apis%2Fwit%2Fsendmail%3Fapi-version%3D7.1-preview.1&redirect=xxxxxxxxxxxxxxxxx'
* Switch from POST to GET
* Trying xx.xxx.xx.xx:443...
* Connected to xxxxx.vssps.visualstudio.com (xx.xxx.xx.xx:443) port 443 (#1)
我使用下面的 PowerShell 脚本来调用
POST https://dev.azure.com/{organization}/{project}/_apis/wit/sendmail?api-version=7.1-preview.1
并按预期收到电子邮件。
$myorg="organization_name"
$myproject="project_name"
$pat="Base64 converted PAT"
$endpoint="https://dev.azure.com/$myorg/$myproject/_apis/wit/sendmail?api-version=7.1-preview.1"
$body='{
"ids": [work item id],
"message": {
"body": "Test Body",
"cc": {},
"to": {
"tfIds": ["your tfId"]
},
"replyTo": {},
"subject": "Test Subject"
}
}'
Invoke-RestMethod -Uri $endpoint -Method POST -Body $body -Headers @{Authorization=("Basic $pat")} -ContentType "application/json"
请添加
ids
作为工作项 ID,并在请求正文中更正 tfIds
。
电子邮件-
参考资料:- Azure DevOps SendMail Rest API 返回 204 但不发送电子邮件 - 堆栈内存溢出