0

我在让我的 ColdFusion 应用程序使用 API 密钥与 Sendgrid 的 v2 API 集成时遇到问题。我的解决方案多年来一直使用用户名/密码,但随着切换到 API 密钥,我无法弄清楚有些不对劲。我尝试了一些不同的配置,但到目前为止没有一个有效:

<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json?api_user=apikey&api_key=[my key]" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="formField" name="api_user" value="apikey">
<cfhttpparam type="formField" name="api_key" value="[my key]">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="header" name="api_user" value="apikey">
<cfhttpparam type="header" name="api_key" value="[my key]">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="cgi" name="api_user" value="apikey">
<cfhttpparam type="cgi" name="api_key" value="[my key]">
</cfhttp>

帮助?

4

1 回答 1

1

我想我想通了。在这个代码库中闲逛之后:

https://github.com/mjclemente/sendgrid.cfc/blob/master/sendgrid.cfc

...看起来语法需要是:

<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="header" name="Authorization" value="Bearer [my key]">
</cfhttp>
于 2020-11-20T16:17:02.007 回答