gpt4 book ai didi

Azure DevOps SendMail Rest API 返回 204 但不发送电子邮件

转载 作者:行者123 更新时间:2023-12-03 06:44:46 32 4
gpt4 key购买 nike

我正在尝试使用以下 SendMail Azure DevOps Rest API 路由在 PowerShell 中发送电子邮件:

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/send-mail/send-mail?view=azure-devops-rest-7.1#emailrecipients

这是我用于此请求的 JSON 正文:

{
"message" : {
"body": "<p>Test Email</p>",
"to" : {
"tfIds" : ["mytfsid here"]
},
"cc" : {},
"replyTo" : {},
"inReplyTo" : "",
"subject" : "test"
},
"projectId" : "my project id here"
}

postman 向我显示我的请求通过了 204;但是,我没有收到任何电子邮件。我不知所措。谁能告诉我我做错了什么,或者为什么电子邮件无法发送?

提前致谢。


What I've tried:

- Tried using the tfId of a colleague; still no e-mail received
- Tried using emailAddresses instead within the "to" block; still does not work.
- Tried using emailAddresses AND tfIds within the "to" block; still does not work.

最佳答案

请确保通知正常工作,否则您必须先解决通知问题。请参阅Why am I not receiving notification emails?

如果通知效果良好,请尝试以下 PowerShell 脚本来发送所选工作项目的电子邮件:(对我有用)

Param(
[string]$orgname = "{org-name}",
[string]$project = "{project-name}",
[string]$sendmailto = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="60181818201818184e030f0d" rel="noreferrer noopener nofollow">[email protected]</a>",
[string]$mysubject = "Test-Subject",
[string]$mailbody = "Body test",
[string]$witids = "1536,1537",
[string]$user = "",
[string]$token = "PAT"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#Get the tfsid
$userentitlementurl = "https://vsaex.dev.azure.com/$orgname/_apis/userentitlements?api-version=7.1-preview.1"
$response = Invoke-RestMethod -Uri $userentitlementurl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

#Filter by sendmailto
$tfsid = ($response.value| where {$_.user.mailAddress -eq $sendmailto}).id
#Create Jason body
function CreateJsonBody
{
$value = @"
{
"message": "{\"to\":{\"tfIds\":[\"$tfsid\"],\"emailAddresses\":[],\"unresolvedEntityIds\":[]},\"subject\":\"$mysubject\",\"body\":\"$mailbody\",\"cc\":{\"tfids\":[\"$tfsid\"]},\"replyTo\":{\"tfids\":[\"$tfsid\"]}}",
"ids": [
$witids
],
"fields": [
"System.Id",
"System.Title",
"System.AssignedTo",
"System.State",
"System.AreaPath",
"System.Tags",
"System.CommentCount"
],
"format": 1
}
"@

return $value
}

$json = CreateJsonBody

$baseurl = "https://dev.azure.com/$orgname/$project/_api/_wit/sendMail?api-version=7.1-preview.1"

#Send mail
Invoke-RestMethod -Uri $baseurl -Method POST -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

enter image description here

关于Azure DevOps SendMail Rest API 返回 204 但不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74198174/

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