-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d59a7a8
Showing
9 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# [Mailjet](https://mailjet.com) addon for [Materia Designer](https://getmateria.com) | ||
|
||
Send email in your Materia application (https://getmateria.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Mailjet { | ||
constructor(app, config) { | ||
this.app = app | ||
this.config = config | ||
} | ||
|
||
getModule() { return "web/js/main.js" } | ||
getTemplate() { return "web/index.html" } | ||
|
||
getInstallTemplate() { return "web/install.html" } | ||
getInstallCtrl() { return "UserManagementInstallCtrl" } | ||
|
||
start() {} | ||
|
||
uninstall(app) {} | ||
} | ||
|
||
module.exports = Mailjet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@materia/mailjet", | ||
"version": "0.1.0", | ||
"description": "Send emails in your application using Mailjet", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "materia start --prod", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"materia": { | ||
"display_name": "Mailjet", | ||
"logo": "https://pbs.twimg.com/profile_images/811557097758461952/Q679jb7i.jpg", | ||
"setup": [ | ||
{ | ||
"name": "apikey", | ||
"description": "Enter your apikey", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "secret", | ||
"description": "Enter your secret key", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "from", | ||
"description": "Enter the email address (sender) attached with your apikey", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "name", | ||
"description": "Enter the name you would like to see appear on your email", | ||
"type": "string" | ||
} | ||
|
||
] | ||
}, | ||
"dependencies": { | ||
"node-mailjet": "^3.0.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class MailjetSender { | ||
constructor(key, secret, from, name) { | ||
this.from = from | ||
|
||
this.mailjet = require('node-mailjet').connect(key, secret); | ||
} | ||
|
||
send(params) { | ||
var sendEmail = this.mailjet.post('send'); | ||
|
||
var emailData = { | ||
'FromEmail': this.from, | ||
'Subject': params.subject, | ||
'Text-part': params.body, | ||
'Recipients': [{'Email': params.to}] | ||
} | ||
if (this.name) { | ||
emailData['FromName'] = this.name | ||
} | ||
|
||
return sendEmail.request(emailData) | ||
} | ||
} | ||
|
||
module.exports = MailjetSender |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"id": "ea2047c9-dbed-443c-a6dd-348a0721b377", | ||
"fields": [ | ||
{ | ||
"name": "id_email", | ||
"type": "number", | ||
"read": true, | ||
"write": false, | ||
"primary": true, | ||
"unique": true, | ||
"required": true, | ||
"autoIncrement": true, | ||
"component": "input" | ||
}, | ||
{ | ||
"name": "body", | ||
"type": "text", | ||
"read": true, | ||
"write": true, | ||
"component": "markdown" | ||
}, | ||
{ | ||
"name": "to", | ||
"type": "text", | ||
"read": true, | ||
"write": true, | ||
"required": true, | ||
"component": "email" | ||
}, | ||
{ | ||
"name": "from", | ||
"type": "text", | ||
"read": true, | ||
"write": true, | ||
"required": true, | ||
"component": "email" | ||
}, | ||
{ | ||
"name": "subject", | ||
"type": "text", | ||
"read": true, | ||
"write": true, | ||
"component": "input" | ||
}, | ||
{ | ||
"name": "date_sent", | ||
"type": "date", | ||
"read": true, | ||
"write": true, | ||
"required": true, | ||
"component": "dateTimePicker" | ||
} | ||
], | ||
"relations": [], | ||
"queries": [ | ||
{ | ||
"id": "send", | ||
"type": "custom", | ||
"opts": { | ||
"params": [ | ||
{ | ||
"name": "to", | ||
"type": "text", | ||
"required": true, | ||
"component": "email" | ||
}, | ||
{ | ||
"name": "subject", | ||
"type": "text", | ||
"component": "input" | ||
}, | ||
{ | ||
"name": "body", | ||
"type": "text", | ||
"component": "textarea" | ||
} | ||
], | ||
"action": "send", | ||
"model": "email" | ||
} | ||
}, | ||
{ | ||
"id": "latest", | ||
"type": "findAll", | ||
"opts": { | ||
"select": [ | ||
"id_email", | ||
"body", | ||
"to", | ||
"from", | ||
"subject", | ||
"date_sent" | ||
], | ||
"conditions": [], | ||
"include": [], | ||
"orderBy": [ | ||
{ | ||
"field": "date_sent", | ||
"desc": true | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const MailjetSender = require('../../lib/mailjet') | ||
|
||
class EmailModel { | ||
constructor(app, entity) { | ||
this.app = app; | ||
this.entity = entity; | ||
this.emailSender = new MailjetSender(app.addons.addonsConfig['mailjet'].apikey, app.addons.addonsConfig['mailjet'].secret, app.addons.addonsConfig['mailjet'].from, app.addons.addonsConfig['mailjet'].name) | ||
} | ||
|
||
send(params) { | ||
return this.emailSender.send(params).then(() => { | ||
params.from = this.app.addons.addonsConfig['mailjet'].from | ||
params.date_sent = new Date() | ||
return this.entity.getQuery('create') | ||
.run(params) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = EmailModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div ng-controller="EmailCtrl" layout="column" flex> | ||
<div layout="row"> | ||
<div md-colors="{background: 'deep-orange'}" style="width: 120px; padding: 10px 0 18px"> | ||
<div style="text-align: center; font-size: 2.5em">{{nbEmails}}</div> | ||
<div style="text-align: center">email{{ nbEmails > 1 ? 's' : '' }} sent</div> | ||
</div> | ||
<div style="padding-top: 15px; margin-left: 20px" flex ng-show="app.addons.addonsConfig['mailjet'].from && app.addons.addonsConfig['mailjet'].apikey"> | ||
Emails are sent from <strong>{{app.addons.addonsConfig['mailjet'].from}}</strong> with <strong>Mailjet</strong> | ||
<br>using the following Mailjet APIKey: <strong>{{app.addons.addonsConfig['mailjet'].apikey.substr(0, 5) + '*****' + app.addons.addonsConfig['mailjet'].apikey.substr(-5, 5)}}</strong> | ||
<br><a href="#">Edit the configuration</a> | ||
</div> | ||
<div style="padding-top: 15px; margin-left: 20px" flex ng-show="app.addons.addonsConfig['mailjet'].from && app.addons.addonsConfig['mailjet'].apikey"> | ||
You need to configure this addon to send email in your application. | ||
<br><a href="#">Configure it now!</a> | ||
</div> | ||
</div> | ||
<md-card flex> | ||
<md-card-header> | ||
<md-card-header-text> | ||
<span class="md-title">Latest emails sent</span> | ||
</md-card-header-text> | ||
</md-card-header> | ||
<md-list> | ||
<md-list-item ng-repeat="email in emails" layout="row"> | ||
<div style="overflow: hidden; text-overflow: ellipsis; width:190px; padding-right: 10px"><strong>{{ email.to }}</strong></div> | ||
<span style="overflow: hidden; text-overflow: ellipsis;" flex> | ||
<strong>{{ email.subject }}</strong> - {{ email.body }} | ||
</span> | ||
<span style="width: 100px">{{email.date_sent | date}}</span> | ||
</md-list-item> | ||
</md-list> | ||
</md-card> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
let mailjet = angular.module('mailjet', [ | ||
'ngResource', | ||
'ngSanitize', | ||
'ngMessages', | ||
'ngAnimate' | ||
]).controller('MailjetCtrl', ($scope, $rootScope) => { | ||
$rootScope.app.entities.get('email').getQuery('latest').run().then(emails => { | ||
console.log('emails', emails) | ||
$scope.emails = emails.data | ||
$scope.nbEmails = emails.count | ||
$scope.$apply() | ||
}).catch(e => { | ||
console.log('error', e, e.stack) | ||
}) | ||
console.log('in app !', $rootScope.app) | ||
}).controller('EmailInstallCtrl', ($scope, $rootScope) => { | ||
|
||
}) | ||
module.exports = mailjet |