1 2 3 | import com.sendgrid.SendGrid; import com.sendgrid.SendGrid.Email; import com.sendgrid.SendGridException; |
1 2 3 4 5 6 7 8 9 | final String VCAP_SERVICES = System.getenv("VCAP_SERVICES"); if (VCAP_SERVICES != null) { JSONObject vcap = new JSONObject(VCAP_SERVICES); JSONArray sendgrid = (JSONArray) vcap.get("sendgrid"); JSONObject json = sendgrid.getJSONObject(0); JSONObject credentials = json.getJSONObject("credentials"); String username = credentials.getString("username"); String password = credentials.getString("password"); } |
1 | Email email = new Email(); |
1 2 3 4 5 6 | email.addTo("david@sendgridtest.com"); email.addToName("David"); email.setFrom("sendgriddemo@sendgridtest.com"); email.setFromName("SendGrid Demo"); email.setSubject("Hello World"); email.setText("Hello, \n This is a test email sent from IBM Bluemix SendGrid service"); |
1 | SendGrid sendgrid = new SendGrid(<user_name>, <password>); |
1 | sendgrid.send(email); |
1 | email.addFilter(<filter_name>, <parameter_name>, <parameter_value>); |
1 2 3 | email.addFilter("footer", "enable", "1"); email.addFilter("footer", "text/html", "<p>Thanks,<br/> The IBM Bluemix Team<p>"); email.addFilter("footer", "text/plain", "Thanks,\n IBM Bluemix Team"); |
1 2 | email.setHtml("Hello, <p>Please visit <a href='https://ace.ng.bluemix.net'>IBM Bluemix</a>.</p>"); email.addFilter("clicktrack", "enable", "1"); |
1 | email.addCategory("marketing"); |
1 | email.addUniqueArg(<key>, <val>); |
1 2 3 4 5 6 7 8 9 10 11 | // Create HTML content email.setHtml("Hello -name-,<br>"); // Specify substitution value for the '-name-' tag defined in the HTML body String[] val = { "SendGridUser" }; email.addSubstitution("-name-", val); // Enable template email.addFilter("templates", "enable", "1"); email.addFilter("templates", "template_id", "ffce1668-6d89-4687-807d-013ae59d5b79 "); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |