Skip to content

Commit

Permalink
correct usage of node-mailjet. I mean, WTF? (fixes #85)
Browse files Browse the repository at this point in the history
  • Loading branch information
meriadec committed Mar 25, 2017
1 parent 5123521 commit 60e18cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
39 changes: 17 additions & 22 deletions services.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const request = require('request')
const Mailjet = require('node-mailjet')
const nodeMailjet = require('node-mailjet')

const dataFolder = process.env.NODE_ENV === 'development'
? app.getAppPath()
Expand Down Expand Up @@ -40,27 +40,22 @@ exports.takeSnapshot = (id, html, done) => {
}

exports.send = function (options, success, error) {
new Mailjet(options.apiKey, options.apiSecret)
.post('send')
.request({
FromName: options.name,
FromEmail: options.sender,
To: options.to,
Subject: 'Test Email',
'Html-Part': options.html,
}, (err, res) => {
if (err && err.message) {
error(err.message)
} else if (err && err.ErrorMessage) {
error(err.ErrorMessage)
} else if (res.statusCode === 401) {
error('Not Authorized')
} else if (err) {
error('There wre a problem while sending your email')
} else {
success()
}
})

const Mailjet = nodeMailjet.connect(options.apiKey, options.apiSecret)
const sendEmail = Mailjet.post('send')

const emailData = {
FromEmail: options.sender,
FromName: options.name,
Subject: 'Test email',
'Html-part': options.html,
Recipients: [{ Email: options.to }],
}

sendEmail.request(emailData)
.then(success)
.catch(error)

}

exports.createGist = function (content, done) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditorSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class EditorSend extends Component {
<div className='form-group' style={{
opacity: this.isValid() ? 1 : 0.4,
}}>
<button type='submit' className='Button primary' disabled={!this.isValid()}>
<button onClick={this.sendEmail} type='submit' className='Button primary' disabled={!this.isValid()}>
{'Send'}
</button>
</div>
Expand Down

0 comments on commit 60e18cc

Please sign in to comment.