diff --git a/package.json b/package.json index 43500f62..1439e6f3 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "koa-router": "^5.4.0", "lodash": "^4.3.0", "lodash.flatmap": "^4.2.0", + "mandrill-api": "^1.0.45", "marked": "^0.3.6", "react": "^15.2.0", "react-addons-css-transition-group": "^15.3.2", diff --git a/server/app.js b/server/app.js index 2cd521a8..2f18222b 100644 --- a/server/app.js +++ b/server/app.js @@ -28,8 +28,12 @@ export default class App extends KoaApp { } start() { + if (process.env.MAILCHIMP_API_KEY === undefined) { + throw new Error(`Can't load MAILCHIMP_API_KEY from environment.`); + } const port = process.env.LISTEN_PORT ? Number(process.env.LISTEN_PORT) : 4045; + this.listen(port); console.info(`Listening on port ${port}`); } diff --git a/src/pages/custom/custom.jsx b/src/pages/custom/custom.jsx index 796a9be2..09d15246 100644 --- a/src/pages/custom/custom.jsx +++ b/src/pages/custom/custom.jsx @@ -2,14 +2,53 @@ import React, { Component } from 'react'; import type { HTMLElement } from 'types'; +import { autobind } from 'core-decorators'; import styles from './custom.css'; import { Form, FormField } from 'ui/forms'; import { TextInput } from 'ui/inputs'; import Button from 'ui/buttons'; +import mandrill from 'mandrill-api/mandrill'; +type State = { + mandrill_client: any +} class Custom extends Component { + state: Props; + + //const mandrill_client = + componentWillMount() { + console.log("Our Key:" + process.env.MAILCHIMP_API_KEY); + this.setState({ + mandrill_client: new mandrill.Mandrill(process.env.MAILCHIMP_API_KEY) + }); + } + + @autobind + sendCustomEmail() { + let message = { + "html": "

TopDrawer Custom Sock Request

The details are below.

", + "text": "Top Drawer Custom Sock Request. The details are below.", + "from_email": "marketing.team@topdrawer.com", + "to": "adil@adilwali.com" + } + + let async = false; + let ip_pool = "Main Pool"; + let send_at = "example send_at"; + + console.log("WE ARE SENDING!"); + this.state.mandrill_client.messages.send({ + "message": message, + "async": async + }, function(result) { + console.log(result); + }, function(e) { + console.log('A mandrill error occured:' + e.name + ' - ' + e.message); + }) + } + get topBanner(): HTMLElement { return (
@@ -70,7 +109,7 @@ class Custom extends Component { />
- +