Add /_lib/get_nodemailer.jst
[ndcode_site.git] / api / contact / send_enquiry.json.jst
index da3ff60..edf8f55 100644 (file)
@@ -1,8 +1,8 @@
-let nodemailer = require('nodemailer')
 let XDate = require('xdate')
 
-return async env => {a
+return async env => {
   let get_globals = await _require('/_lib/get_globals.jst')
+  let get_nodemailer = await _require('/_lib/get_nodemailer.jst')
   let get_session = await _require('/_lib/get_session.jst')
   let post_request = await _require('/_lib/post_request.jst')
   let Problem = await _require('/_lib/Problem.jst')
@@ -32,18 +32,12 @@ return async env => {a
         )
 
       let transaction = await env.site.database.Transaction()
-      let nodemailer_contact, contact_from, contact_to
+      let nodemailer, contact_from, contact_to
       try {
         // initialize env.session_key, set cookie in env.response
         get_session(env, transaction)
 
-        nodemailer_contact = nodemailer.createTransport(
-          await (
-            await (
-              await transaction.get({})
-            ).get('nodemailer')
-          ).get_json('contact')
-        )
+        nodemailer = await get_nodemailer(env, transaction, 'contact')
         let globals = await get_globals(env, transaction)
         contact_from = await globals.get_json('contact_from')
         contact_to = await globals.get_json('contact_to')
@@ -63,7 +57,7 @@ return async env => {a
         details.company.length ?
           `Enquiry: ${details.company}` :
           'Enquiry'
-      await nodemailer_contact.sendMail(
+      await nodemailer.sendMail(
         {
           from: contact_from,
           to: contact_to,