{"id":8471,"date":"2017-09-28T12:07:11","date_gmt":"2017-09-28T03:07:11","guid":{"rendered":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=8471"},"modified":"2023-09-06T11:18:59","modified_gmt":"2023-09-06T02:18:59","slug":"kotlin%e3%81%8b%e3%82%89sendgrid%e3%82%92%e5%88%a9%e7%94%a8%e3%81%97%e3%81%a6%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=8471","title":{"rendered":"Kotlin\u304b\u3089SendGrid\u3092\u5229\u7528\u3057\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2017\/09\/logo-text.png\" alt=\"logo-text\" width=\"100%\" class=\"aligncenter size-full wp-image-8472\" style=\"box-shadow: 0 0 0px\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2017\/09\/logo-text.png 2250w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2017\/09\/logo-text-300x67.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2017\/09\/logo-text-768x171.png 768w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2017\/09\/logo-text-1024x228.png 1024w\" sizes=\"(max-width: 2250px) 100vw, 2250px\" \/><\/p>\n<p>SendGrid\u30b5\u30dd\u30fc\u30c8\u30c1\u30fc\u30e0\u306e\u83ca\u7530(<a href=\"https:\/\/twitter.com\/kikutaro_\" target=\"_blank\">@kikutaro_<\/a>)\u3067\u3059\u3002\u5148\u65e5\u3001\u4eca\u5e74\u958b\u50ac\u3055\u308c\u308b\u300c<a href=\"https:\/\/www.oracle.com\/javaone\/index.html\" target=\"_blank\">JavaOne<\/a>\u300d\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u3064\u3044\u3066\u8abf\u3079\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3075\u3068\u6c17\u306b\u306a\u3063\u3066\u300c<a href=\"https:\/\/kotlinlang.org\/\" target=\"_blank\">Kotlin<\/a>\u300d\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u8abf\u3079\u305f\u3068\u3053\u308d12\u4ef6\u3042\u308a\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u53bb\u5e74\u306b\u6bd4\u3079\u3066\u500d\u304f\u3089\u3044\u306e\u6570\u3067\u3059\u3002\u307e\u305f\u3001\u4eca\u5e74\u306e11\u6708\u306b\u306f\u300c<a href=\"https:\/\/kotlinconf.com\/\" target=\"_blank\">KotlinConf<\/a>\u300d\u3068\u3044\u30462\u65e5\u9593\u306b\u6e21\u308b\u30ab\u30f3\u30d5\u30a1\u30ec\u30f3\u30b9\u304c\u958b\u50ac\u3055\u308c\u308b\u306a\u3069\u3001\u958b\u767a\u8005\u306e\u9593\u3067Kotlin\u3078\u306e\u6ce8\u76ee\u5ea6\u304c\u5897\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u5927\u304d\u306a\u8981\u56e0\u3068\u3057\u3066\u3001\u4eca\u5e745\u6708\u306b\u958b\u50ac\u3055\u308c\u305f\u300c<a href=\"https:\/\/events.google.com\/io\/\" target=\"_blank\">Google I\/O 2017<\/a>\u300d\u3067Android\u30a2\u30d7\u30ea\u306e\u516c\u5f0f\u958b\u767a\u8a00\u8a9e\u306bKotlin\u304c\u52a0\u308f\u3063\u305f\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/kotlinlang.org\/\" target=\"_blank\">Kotlin<\/a>\u306fJava\u4eee\u60f3\u30de\u30b7\u30f3\u4e0a\u3067\u52d5\u4f5c\u3059\u308bJVM\u8a00\u8a9e\u306e1\u3064\u3067\u3001\u9759\u7684\u578b\u4ed8\u3051\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e\u3067\u3059\u3002<a href=\"https:\/\/www.jetbrains.com\/idea\/\" target=\"_blank\">IntelliJ IDEA<\/a>\u3084<a href=\"https:\/\/www.jetbrains.com\/resharper\/\" target=\"_blank\">ReSharper<\/a>\u306a\u3069\u306e\u958b\u767a\u8005\u5411\u3051\u88fd\u54c1\u3067\u6709\u540d\u306a<a href=\"https:\/\/www.jetbrains.com\/\" target=\"_blank\">Jet Brains<\/a>\u306b\u3088\u3063\u3066\u958b\u767a\u3055\u308c\u307e\u3057\u305f\u3002\u578b\u63a8\u8ad6\u3084null\u5b89\u5168\u3001\u30bb\u30df\u30b3\u30ed\u30f3\u30ec\u30b9\u306a\u3069\u306e\u6a5f\u80fd\u304c\u63c3\u3063\u3066\u3044\u3066\u3001Java\u3088\u308a\u7c21\u6f54\u306b\u8a18\u8ff0\u3067\u304d\u308b\u306e\u304c\u7279\u5fb4\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30d6\u30ed\u30b0\u3067\u306fKotlin\u3092\u4f7f\u3063\u3066SendGrid\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<blockquote><p>\n\u52d5\u4f5c\u78ba\u8a8d\u74b0\u5883\u3084\u5b9f\u969b\u306b\u8a66\u3057\u305f\u30b3\u30fc\u30c9\u306f<a href=\"https:\/\/github.com\/kikutaro\/SendGridKotlin\" target=\"_blank\">\u3053\u3061\u3089\u3092\u53c2\u7167<\/a>\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n<\/p><\/blockquote>\n<h3>Kotlin x HTTP Client\u3067\u30e1\u30fc\u30eb\u9001\u4fe1<\/h3>\n<p>SendGrid\u304c\u516c\u958b\u3057\u3066\u3044\u308b<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/API_Reference\/Web_API_v3\/index.html\" target=\"_blank\">Web API v3<\/a>\u3092\u5229\u7528\u3057\u3066\u3001\u307e\u305a\u306f\u30b7\u30f3\u30d7\u30eb\u306bHTTP\u3067API\u3092\u30b3\u30fc\u30eb\u3057\u3066\u307f\u307e\u3059\u3002<a href=\"https:\/\/kotlinlang.org\/docs\/resources.html\" target=\"_blank\">Kotlin\u95a2\u9023\u306e\u30e9\u30a4\u30d6\u30e9\u30ea<\/a>\u306f\u65e2\u306b\u8272\u3005\u306a\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u3053\u306e\u4e2d\u304b\u3089<a href=\"https:\/\/github.com\/kittinunf\/Fuel\" target=\"_blank\">Fuel<\/a>\u3068\u3044\u3046HTTP Client\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u8a66\u3057\u305f\u306e\u306f\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u3059\u3002\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3084API\u30ad\u30fc\u306f\u30c0\u30df\u30fc\u306b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u9069\u5b9c\u8aad\u307f\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\npackage jp.co.kke.sendgrid.kotlin\r\n\r\nimport com.github.kittinunf.fuel.core.FuelManager\r\nimport com.github.kittinunf.fuel.httpPost\r\nimport com.github.kittinunf.result.Result\r\n\r\nfun main(args : Array&lt;String&gt;) {\r\n    var to = &quot;to@example.com&quot;\r\n    var from = &quot;from@example.com&quot;\r\n    var fromName = &quot;SenderKotlin&quot;\r\n\r\n    var content = &quot;&quot;&quot;\r\n    {\r\n        &quot;personalizations&quot;: &#x5B;\r\n            {\r\n                &quot;to&quot;: &#x5B;\r\n                    {\r\n                        &quot;email&quot;: &quot;$to&quot;\r\n                    }\r\n                ]\r\n            }\r\n        ],\r\n        &quot;from&quot;: {\r\n            &quot;email&quot;: &quot;$from&quot;,\r\n            &quot;name&quot;: &quot;$fromName&quot;\r\n        },\r\n        &quot;subject&quot;: &quot;\u30c6\u30b9\u30c8&quot;,\r\n        &quot;content&quot;: &#x5B;\r\n            {\r\n                &quot;type&quot;: &quot;text\/plain&quot;,\r\n                &quot;value&quot;: &quot;Kotlin\u304b\u3089\u9001\u3063\u305f&quot;\r\n            },\r\n            {\r\n                &quot;type&quot;: &quot;text\/html&quot;,\r\n                &quot;value&quot;: &quot;&lt;html&gt;&lt;body&gt;Kotlin\u304b\u3089\u9001\u3063\u305f&lt;\/body&gt;&lt;\/html&gt;&quot;\r\n            }\r\n        ]\r\n    }\r\n    &quot;&quot;&quot;\r\n\r\n    FuelManager.instance.baseHeaders = mapOf(&quot;Content-Type&quot; to &quot;application\/json&quot;, &quot;Authorization&quot; to &quot;Bearer *****API\u30ad\u30fc*****&quot;)\r\n    &quot;https:\/\/api.sendgrid.com\/v3\/mail\/send&quot;.httpPost().body((content)).response { req, res, result -&gt;\r\n        when(result) {\r\n            is Result.Failure -&gt; {\r\n                println(&quot;API\u306e\u30b3\u30fc\u30eb\u306b\u5931\u6557&quot;)\r\n            }\r\n            is Result.Success -&gt; {\r\n                when(res.httpStatusCode) {\r\n                    202 -&gt; println(&quot;\u30e1\u30fc\u30eb\u9001\u4fe1\u6210\u529f&quot;)\r\n                    400, 401, 413 -&gt; println(&quot;SendGrid\u304b\u3089400\u756a\u53f0\u306e\u30a8\u30e9\u30fc\u30b3\u30fc\u30c9\u304c\u8fd4\u3063\u3066\u304d\u305f&quot;)\r\n                    else -&gt; println(&quot;\u60f3\u5b9a\u3057\u3066\u3044\u306a\u3044\u30b3\u30fc\u30c9\u304c\u8fd4\u3063\u3066\u304d\u305f&quot;)\r\n                }\r\n            }\r\n        }\r\n        println(req)\r\n        println(res)\r\n        println(result)\r\n    }\r\n}\r\n<\/pre>\n<h4>\u30c8\u30ea\u30d7\u30eb\u30af\u30a9\u30fc\u30c8\u306b\u3088\u308b\u6587\u5b57\u5217\u5b9a\u7fa9<\/h4>\n<p>\u524d\u534a\u90e8\u5206\u3001JSON\u5f62\u5f0f\u3067\u30e1\u30fc\u30eb\u9001\u4fe1\u60c5\u5831\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002Kotlin\u3067\u306f<a href=\"https:\/\/kotlinlang.org\/docs\/reference\/basic-types.html#strings\" target=\"_blank\">\u30c8\u30ea\u30d7\u30eb\u30af\u30a9\u30fc\u30c8\uff08\u201d\u201d\u201d\uff09<\/a>\u3067\u6587\u5b57\u5217\u3092\u631f\u3080\u3053\u3068\u3067\u751f\u6587\u5b57\u5217\uff08Raw String\uff09\u3092\u5ba3\u8a00\u3067\u304d\u308b\u305f\u3081\u3001\u30a8\u30b9\u30b1\u30fc\u30d7\u306a\u3057\u3067\u76f4\u89b3\u7684\u306bJSON\u30c7\u30fc\u30bf\u3092\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002Java\u3067\u306f\u30c8\u30ea\u30d7\u30eb\u30af\u30a9\u30fc\u30c8\u306e\u3088\u3046\u306a\u8868\u73fe\u306f\u306a\u3044\u305f\u3081\u3001\u540c\u3058\u3088\u3046\u306b\u5b9a\u7fa9\u3059\u308b\u3068\u4e8c\u91cd\u5f15\u7528\u7b26\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\uff08\\\u201d\uff09\u3084\u6539\u884c\u306b\u4f34\u3046\u6587\u5b57\u5217\u306e\u9023\u7d50\uff08+\uff09\u306a\u3069\u304c\u5165\u308a\u3001\u3069\u3046\u3057\u3066\u3082\u898b\u3065\u3089\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/Java\u306e\u4f8b\r\nString content = \r\n    &quot;{&quot; \r\n    +&quot;\\&quot;personalizations\\&quot;: &#x5B;&quot;\r\n    +&quot;{&quot;\r\n\u3000\u3000\/\/\u2026\u2026\u4ee5\u4e0b\u7565\r\n<\/pre>\n<p>\u5b9f\u969b\u306e\u30b7\u30b9\u30c6\u30e0\u3067\u306f\u76f4\u63a5\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u30e1\u30fc\u30eb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6587\u5b57\u5217\u3092\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3001JSON\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30de\u30c3\u30d1\u30fc\u3092\u5229\u7528\u3057\u305f\u308a\u3057\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u3042\u307e\u308a\u6c17\u306b\u306a\u3089\u306a\u3044\u90e8\u5206\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u4eca\u56de\u306e\u3088\u3046\u306a\u3061\u3087\u3063\u3068\u3057\u305f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u4e0a\u3067\u306f\u5b09\u3057\u3044\u8868\u73fe\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h4>String Templates\u306b\u3088\u308b\u5909\u6570\u306e\u5dee\u3057\u8fbc\u307f<\/h4>\n<p>JSON\u6587\u5b57\u5217\u306e\u4e2d\u3067\u306f\u300c$to\u300d\u300c$from\u300d\u300c$fromName\u300d\u3068\u3044\u3063\u305f\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u5192\u982d\u306b\u5ba3\u8a00\u3057\u305f\u5909\u6570\u306e\u5024\u3092\u305d\u308c\u305e\u308c\u5dee\u3057\u8fbc\u3080\u3053\u3068\u3092\u610f\u5473\u3057\u3001<a href=\"https:\/\/kotlinlang.org\/docs\/reference\/basic-types.html#string-templates\" target=\"_blank\">String Templates<\/a>\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u3067\u3059\u3002SendGrid\u3067\u3082<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/API_Reference\/Web_API_v3\/Mail\/index.html#-Request-Body-Parameters\" target=\"_blank\">substitutions<\/a>\u3092\u5229\u7528\u3057\u305f\u5024\u306e\u5dee\u3057\u8fbc\u307f\u304c\u53ef\u80fd\u306a\u306e\u3067\u3001\u3046\u307e\u304f\u4f7f\u3044\u5206\u3051\u306a\u304c\u3089\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u69d8\u3005\u306a\u30d1\u30bf\u30fc\u30f3\u306e\u5dee\u3057\u8fbc\u307f\u3092\u5b9f\u73fe\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n<h4>Collection (mapOf\u306e\u5229\u7528)<\/h4>\n<p>Kotlin\u306f<a href=\"https:\/\/kotlinlang.org\/api\/latest\/jvm\/stdlib\/index.html\" target=\"_blank\">\u8c4a\u5bcc\u306a\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea<\/a>\u3092\u63c3\u3048\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f<a href=\"https:\/\/kotlinlang.org\/api\/latest\/jvm\/stdlib\/kotlin.collections\/index.html\" target=\"_blank\">Collection<\/a>\u3092\u5229\u7528\u3057\u3066HTTP\u30d8\u30c3\u30c0\u306e\u5024\uff08<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/API_Reference\/Web_API_v3\/How_To_Use_The_Web_API_v3\/requests.html#-Authorization-Header\" target=\"_blank\">Authorization\u30d8\u30c3\u30c0<\/a>\u3084<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/API_Reference\/Web_API_v3\/How_To_Use_The_Web_API_v3\/requests.html#-Accept-Header\" target=\"_blank\">Accept\u30d8\u30c3\u30c0<\/a>\u306a\u3069\uff09\u3092\u6b21\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nmapOf(&quot;Content-Type&quot; to &quot;application\/json&quot;, &quot;Authorzation&quot; to &quot;Bearer *****API\u30ad\u30fc*****&quot;)\r\n<\/pre>\n<h4>when\u3092\u4f7f\u3063\u305f\u51e6\u7406\u5206\u5c90<\/h4>\n<p>\u30b3\u30fc\u30c9\u5f8c\u534a\u306ePOST\u30c7\u30fc\u30bf\u3092\u6295\u3052\u308b\u90e8\u5206\u3067\u306f\u3001when\u3092\u4f7f\u3063\u3066API\u30b3\u30fc\u30eb\u7d50\u679c\u306e\u51e6\u7406\u3092\u5206\u5c90\u3057\u3066\u3044\u307e\u3059\u3002Java\u306eSwitch\u6587\u3068\u9055\u3044\u3001\u5f15\u6570\u306a\u3057\u3067\u6b21\u306e\u3088\u3046\u306a\u8a18\u8ff0\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nwhen{\r\n    result is Result.Failure -&gt; {\r\n        println(&quot;API\u306e\u30b3\u30fc\u30eb\u306b\u5931\u6557&quot;)\r\n    }\r\n    result is Result.Success -&gt; {\r\n        \/\/\u6210\u529f\u6642\u306e\u51e6\u7406\r\n    }\r\n}\r\n<\/pre>\n<p>\u307e\u305f\u3001\u5206\u5c90\u6761\u4ef6\u306b\u5f0f\u3092\u5229\u7528\u3067\u304d\u308b\u306a\u3069\u3001\u67d4\u8edf\u6027\u306e\u9ad8\u3044\u8a18\u8ff0\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>Kotlin x SendGrid Java\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u30e1\u30fc\u30eb\u9001\u4fe1<\/h3>\n<p>Kotlin\u306e\u9b45\u529b\u306e1\u3064\u306b\u65e2\u5b58\u306eJava\u8cc7\u7523\u3092\u6d3b\u7528\u3067\u304d\u308b\u70b9\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u4eca\u5ea6\u306f<a href=\"https:\/\/github.com\/sendgrid\/sendgrid-java\" target=\"_blank\">SendGrid\u304c\u516c\u5f0f\u306b\u63d0\u4f9b\u3057\u3066\u3044\u308bJava\u30e9\u30a4\u30d6\u30e9\u30ea<\/a>\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>Kotlin\u3067\u66f8\u304f\u524d\u306bJava\u306e\u30b3\u30fc\u30c9\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002SendGrid\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u3042\u308b<a href=\"https:\/\/github.com\/sendgrid\/sendgrid-java#with-mail-helper-class\" target=\"_blank\">Helper Class\u3092\u5229\u7528\u3057\u305f\u4f8b<\/a>\u3092\u63b2\u8f09\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport com.sendgrid.*;\r\nimport java.io.IOException;\r\n\r\npublic class Example {\r\n  public static void main(String&#x5B;] args) throws IOException {\r\n    Email from = new Email(&quot;test@example.com&quot;);\r\n    String subject = &quot;Sending with SendGrid is Fun&quot;;\r\n    Email to = new Email(&quot;test@example.com&quot;);\r\n    Content content = new Content(&quot;text\/plain&quot;, &quot;and easy to do anywhere, even with Java&quot;);\r\n    Mail mail = new Mail(from, subject, to, content);\r\n\r\n    SendGrid sg = new SendGrid(System.getenv(&quot;SENDGRID_API_KEY&quot;));\r\n    Request request = new Request();\r\n    try {\r\n      request.setMethod(Method.POST);\r\n      request.setEndpoint(&quot;mail\/send&quot;);\r\n      request.setBody(mail.build());\r\n      Response response = sg.api(request);\r\n      System.out.println(response.getStatusCode());\r\n      System.out.println(response.getBody());\r\n      System.out.println(response.getHeaders());\r\n    } catch (IOException ex) {\r\n      throw ex;\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>\u3053\u308c\u3092Kotlin\u306b\u7f6e\u304d\u304b\u3048\u3066\u307f\u307e\u3059\u3002IDE\u306eIntelliJ IDEA\u3092\u4f7f\u3046\u3068\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u30da\u30fc\u30b9\u30c8\u5f8c\u300cKotlin\u3078\u5909\u63db\u3057\u307e\u3059\u304b\uff1f\u300d\u3068\u805e\u304b\u308c\u307e\u3059\u3002Yes\u3092\u9078\u629e\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3078\u81ea\u52d5\u5909\u63db\u3057\u3066\u304f\u308c\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.co.kke.sendgrid.kotlin\r\n\r\nimport com.sendgrid.*\r\nimport java.io.IOException\r\n\r\nfun sendBySendGrid() {\r\n    val from = Email(&quot;test@example.com&quot;)\r\n    val subject = &quot;Sending with SendGrid is Fun&quot;\r\n    val to = Email(&quot;test@example.com&quot;)\r\n    val content = Content(&quot;text\/plain&quot;, &quot;and easy to do anywhere, even with Kotlin&quot;)\r\n    val mail = Mail(from, subject, to, content)\r\n\r\n    val sg = SendGrid(&quot;*****API\u30ad\u30fc*****&quot;)\r\n    val request = Request()\r\n    try {\r\n        request.method = Method.POST\r\n        request.endpoint = &quot;mail\/send&quot;\r\n        request.body = mail.build()\r\n        val response = sg.api(request)\r\n        System.out.println(response.statusCode)\r\n        System.out.println(response.body)\r\n        System.out.println(response.headers)\r\n    } catch (ex: IOException) {\r\n        throw ex\r\n    }\r\n}\r\n<\/pre>\n<p>\u4e0a\u8a182\u3064\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001Java\u3068\u6bd4\u8f03\u3057\u3066\u4e3b\u306b\u6b21\u306e3\u70b9\u304c\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5909\u6570\u5ba3\u8a00\u3067\u578b\u306e\u660e\u793a\u304c\u4e0d\u8981\uff08\u578b\u63a8\u8ad6\uff09<\/li>\n<li>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\u306bnew\u304c\u4e0d\u8981<\/li>\n<li>\u30bb\u30df\u30b3\u30ed\u30f3\u306a\u3057<\/li>\n<\/ul>\n<p>\u5168\u4f53\u7684\u306b\u3059\u3063\u304d\u308a\u3057\u305f\u611f\u3058\u3067\u3059\u304c\u3001\u4e0a\u8a18\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u30ec\u30d9\u30eb\u3060\u3068Java\u3068\u3042\u307e\u308a\u5927\u304d\u306a\u5dee\u304c\u306a\u3044\u305f\u3081\u9762\u767d\u307f\u306f\u8584\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3068\u306f\u3044\u3048\u3001\u3053\u306e\u3088\u3046\u306a\u5f62\u3067Java\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u305d\u306e\u307e\u307e\u5229\u7528\u3067\u304d\u308b\u3053\u3068\u306f\u3001\u65e2\u5b58\u8cc7\u7523\u3092\u6d3b\u304b\u3059\u4e0a\u3067\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3001\u3082\u3063\u3068\u30b9\u30de\u30fc\u30c8\u306b\u66f8\u3051\u308b\u306e\u3067\u306f\uff1f\u3068\u3044\u3046\u65b9\u306f\u662f\u975e100% Pure Kotlin\u306aSendGrid\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066sendgrid4kt\u306e\u3088\u3046\u306a\u3082\u306e\u3092\u4f5c\u3063\u3066\u3044\u305f\u3060\u3051\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\uff01<\/p>\n<h3>\u304a\u308f\u308a\u306b<\/h3>\n<p>\u3044\u304b\u304c\u3067\u3057\u305f\u3067\u3057\u3087\u3046\u304b\u3002\u79c1\u306f\u4eca\u56de\u306f\u3058\u3081\u3066Kotlin\u3092\u89e6\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3068\u3066\u3082\u66f8\u304d\u3084\u3059\u3044\u5370\u8c61\u3092\u53d7\u3051\u307e\u3057\u305f\u3002\u3082\u3061\u308d\u3093\u3001\u57fa\u672c\u306e\u6587\u6cd5\u90e8\u5206\u3057\u304b\u89e6\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u3068\u3044\u3046\u306e\u306f\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4eca\u5f8c\u3082\u89e6\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u306a\u304a\u3001Kotlin\u306fAndroid\u306e\u958b\u767a\u3067\u5229\u7528\u3055\u308c\u308b\u6a5f\u4f1a\u304c\u591a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30e2\u30d0\u30a4\u30eb\u30a2\u30d7\u30ea\u3067SendGrid\u3092\u4f7f\u3046\u969b\u306fAPI\u30ad\u30fc\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30a2\u30d7\u30ea\u5074\u306b\u57cb\u3081\u8fbc\u307e\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u901a\u5e38\u306f\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u5074\u306b\u30e1\u30fc\u30eb\u9001\u4fe1\u6a5f\u80fd\u3092\u6301\u305f\u305b\u308b\u5f62\u304c\u591a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002mBaaS\u306a\u3069\u306e\u74b0\u5883\u3092\u4e0a\u624b\u304f\u6d3b\u7528\u3059\u308c\u3070\u3001\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3068\u306e\u9023\u643a\u3082\u52b9\u7387\u826f\u304f\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u53c2\u8003\uff1a<br \/>\n<a href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=4976\" target=\"_blank\">\u30cb\u30d5\u30c6\u30a3\u30af\u30e9\u30a6\u30c9mobile backend\u3092\u4f7f\u3063\u3066\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5<\/a><br \/>\n<a href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=4473\" target=\"_blank\">Kii\u3092\u4f7f\u3063\u3066\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u304b\u3089\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5<\/a><\/p>\n<p>\u73fe\u5728Kotlin\u306fAndroid\u306b\u9650\u3089\u305a\u3001\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067\u306e\u5229\u7528\u3082\u5897\u3048\u3066\u3044\u308b\u3068\u805e\u304d\u307e\u3059\u3002\u4eca\u6708\u672b\u306b\u306f<a href=\"https:\/\/m3-engineer.connpass.com\/event\/65588\/\" target=\"_blank\">Kotlin x Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u672c\u3082\u51fa\u308b<\/a>\u3088\u3046\u306a\u306e\u3067\u3001\u4eca\u5f8c\u8272\u3005\u3068\u8a66\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SendGrid\u30b5\u30dd\u30fc\u30c8\u30c1\u30fc\u30e0\u306e\u83ca\u7530(@kikutaro_)\u3067\u3059\u3002\u5148\u65e5\u3001\u4eca\u5e74\u958b\u50ac\u3055\u308c\u308b\u300cJavaOne\u300d\u306e\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u3064\u3044\u3066\u8abf\u3079\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3075\u3068\u6c17\u306b\u306a\u3063\u3066\u300cKotlin\u300d\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u8abf\u3079\u305f\u3068\u3053\u308d12\u4ef6\u3042\u308a\u307e\u3057\u305f <a class=\"read-more\" href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=8471\">&#8230;\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":9,"featured_media":8472,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-8471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8471"}],"version-history":[{"count":15,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8471\/revisions"}],"predecessor-version":[{"id":16905,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8471\/revisions\/16905"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/8472"}],"wp:attachment":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}