获取 SendGrid API 键以使用 ColdFusion

Getting SendGrid API Keys to work with ColdFusion

我在使用 API 键将我的 ColdFusion 应用程序与 Sendgrid 的 v2 API 集成时遇到问题。我的解决方案使用 username/password 多年来一直有效,但随着切换到 API 键,出现了一些我无法弄清楚的问题。我已经尝试了几种不同的配置,但 none 到目前为止都有效:

<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>

帮忙?

我想我明白了。浏览此代码库后:

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>