要使用 sendEmail 方法,需要指定一个初始化参数 (SoftLayer_Network_Message_Delivery_Email_SendgridInitParameters),您可以在SoftLayer_Network_Message_Delivery_Email_Sendgrid::sendEmail方法的“必需标头”部分中看到这一点,您可以在此处获取有关初始化参数的更多信息。
因此,您可以使用以下方法获取“SoftLayer_Network_Message_Delivery_Email_Sendgrid”对象:SoftLayer_Account::getNetworkMessageDeliveryAccounts,这里是一个 Rest 请求:
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getNetworkMessageDeliveryAccounts
Method: Get
你会得到这样的结果:
0: {
"accountId": 123456
"createDate": "2015-05-15T06:35:56+12:00"
"id": 24564
"modifyDate": "2016-01-08T05:59:57+11:00"
"password": "Password123*"
"typeId": 21
"username": "newemail@softlayer.com"
"vendorId": 1
"emailAddress": "email@softlayer.com"
"smtpAccess": "1"
}
因此,您需要在您正在使用的服务中指定“id”(SoftLayer_Network_Message_Delivery_Email_Sendgrid)。在 java 中应该是这样的:
Long sendGridId = new Long(24564);
Sendgrid.Service sendgridService = Sendgrid.service(client, sendGridId);
它对我来说不起作用,似乎用于 Java 的 SoftLayer API 客户端在为“SoftLayer_Network_Message_Delivery_Email_Sendgrid”服务指定初始化参数时存在问题。如果您无法为 Java 问题指定此 SoftLayer API 客户端,您可以对其进行验证并提交问题。
事实上,我可以提供一个工作正常的休息请求:
https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Message_Delivery_Email_Sendgrid/24564/sendEmail
Method: Post
{
"parameters":[
{
"body":"set me",
"from":"set me",
"to":"set me",
"subject":"set me"
}
]
}
参考:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Message_Delivery_Email_Sendgrid/sendEmail