2016-02-04 34 views
-1

在Softlayer Portal中,我訂購了電子郵件傳送服務。我可以在列表中看到它。但如何發送電子郵件與Java API。在softlayer上發送郵件

我試圖用下面的代碼發送電子郵件。

Email email = new Email(); 
email.setfrom(); 
email.setBody(); 
email.setTo(); 
Boolean result = service.sendEmail(email);` 

,但它顯示的錯誤是「ID需要調用服務」,如果您共享樣本代碼

,這將是有幫助。 謝謝

回答

1

要使用sendEmail方法,有必要指定一個初始化參數(SoftLayer_Network_Message_Delivery_Email_SendgridInitParameters),你可以在「必需的頭部」部分看到這個從SoftLayer_Network_Message_Delivery_Email_Sendgrid::sendEmail方法,你可以得到有關初始化參數here更多信息。

所以,你可以用下面的方法得到 「SoftLayer_Network_Message_Delivery_Email_Sendgrid」 對象:SoftLayer_Account::getNetworkMessageDeliveryAccounts,這裏休息請求:

https://$username:[email protected]/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": "[email protected]" 
"vendorId": 1 
"emailAddress": "[email protected]" 
"smtpAccess": "1" 
} 

所以,你需要在您使用的服務(SoftLayer_Network_Message_Delivery_Email_Sendgrid)中指定「id」。它應該像這樣在Java:

Long sendGridId = new Long(24564); 
Sendgrid.Service sendgridService = Sendgrid.service(client, sendGridId); 

它不工作對我很好,似乎Java的SoftLayer的API客戶端有問題,指定「SoftLayer_Network_Message_Delivery_Email_Sendgrid」服務初始化參數。如果您無法指定此SoftLayer API Client for Java Issues,則可以驗證並提交問題。

其實,我可以提供工作正常休息的請求:

https://$user:[email protected]/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