From fd2d2f605e0900ba63086c1639ead15ca8210376 Mon Sep 17 00:00:00 2001 From: gregorwolf Date: Tue, 9 Aug 2016 00:24:18 +0200 Subject: [PATCH] Demo to send E-Mail using mailgun.com --- odatapublic/mailgun.xshttpdest | 10 ++++++++++ odatapublic/mailgun.xsjs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 odatapublic/mailgun.xshttpdest create mode 100644 odatapublic/mailgun.xsjs diff --git a/odatapublic/mailgun.xshttpdest b/odatapublic/mailgun.xshttpdest new file mode 100644 index 0000000..42639d3 --- /dev/null +++ b/odatapublic/mailgun.xshttpdest @@ -0,0 +1,10 @@ +host = "api.mailgun.net"; +port = 443; +pathPrefix = "/v3/sandbox864bff1527b245f583ea2373c52f0cc3.mailgun.org"; +proxyType = http; +proxyHost = "proxy-trial"; +proxyPort = 8080; +authType = basic; +useSSL = true; +timeout = 30000; +sslAuth = client; diff --git a/odatapublic/mailgun.xsjs b/odatapublic/mailgun.xsjs new file mode 100644 index 0000000..c551b6d --- /dev/null +++ b/odatapublic/mailgun.xsjs @@ -0,0 +1,30 @@ +var destination_package = "de.linuxdozent.gittest.odatapublic"; +var destination_name = "mailgun"; +var message; +var he; + + +try { + var dest = $.net.http.readDestination(destination_package, destination_name); + var client = new $.net.http.Client(); + + var req = new $.web.WebRequest($.net.http.POST, "/messages"); + req.headers.set('Content-Type', encodeURIComponent("application/x-www-form-urlencoded")); + + req.parameters.set("domain","sandbox864bff1527b245f583ea2373c52f0cc3.mailgun.org"); + req.parameters.set("from","gregor@sandbox864bff1527b245f583ea2373c52f0cc3.mailgun.org"); + req.parameters.set("to","gregor.wolf@gmail.com"); + req.parameters.set("subject","Test subject"); + req.parameters.set("text","Test text"); + + client.request(req, dest); + var response = client.getResponse(); + + + $.response.contentType = "text/html"; + $.response.setBody(response.body.asString()); + $.response.status = $.net.http.OK; +} catch (e) { + $.response.contentType = "text/plain"; + $.response.setBody(e.message); +} \ No newline at end of file