sjs7007 / S3Lab

Code for Deep Cloud back end.
http://deepc05.acis.ufl.edu:8080/
0 stars 0 forks source link

Email updates. #9

Closed sjs7007 closed 8 years ago

sjs7007 commented 8 years ago

Send email updates to user whenever status changes.

Options : Gmail / email service like mailgun gmail, harder to setup, can lead to captcha

using mailgun for now : https://mailgun.com/app/dashboard

sjs7007 commented 8 years ago

curl :

curl -s --user 'api:key-' \
    https://api.mailgun.net/v3/sandbox2796510b356d4fd5a02c639af3080887.mailgun.org/messages \
    -F from='Excited User <postmaster@sandbox2796510b356d4fd5a02c639af3080887.mailgun.org>' \
    -F to=sjs7007@gmail.com \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!'

nodejs using mailgunjs :

console.log("test")

var api_key = '';
var domain = 'sandbox2796510b356d4fd5a02c639af3080887.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

var data = {
  from: 'Excited User <postmaster@sandbox2796510b356d4fd5a02c639af3080887.mailgun.org>',
  to: 'sjs7007@gmail.com',
  subject: 'Hello',
  text: 'Testing some Mailgun awesomness!'
};

mailgun.messages().send(data, function (error, body) {
  console.log(body);
});
sjs7007 commented 8 years ago

Look into kafka :

  1. http://www.ymc.ch/en/whats-an-appropriate-use-case-for-kafka
  2. http://blog.cloudera.com/blog/2014/09/apache-kafka-for-beginners/
  3. http://www.techrepublic.com/article/apache-kafka-is-booming-but-should-you-use-it/
  4. http://www.grokit.ca/cnt/ApacheHadoop/

From first looks seems to be a solution for dealing with live data

Not for user email but use it to create server dashboard tracking different types of jobs going on, loads on server etc maybe.

sjs7007 commented 8 years ago

make email better : send html form along with update to do things like pause, resume, suspend

sjs7007 commented 8 years ago
var domain = 'mydomain.mailgun.org';
var mailgun = require('mailgun-js')({ apiKey: "YOUR API KEY", domain: domain });
var mailcomposer = require('mailcomposer');

var mail = mailcomposer({
  from: 'you@samples.mailgun.org',
  to: 'mm@samples.mailgun.org',
  subject: 'Test email subject',
  body: 'Test email text',
  html: '<b> Test email text </b>'
});

mail.build(function(mailBuildError, message) {

    var dataToSend = {
        to: 'mm@samples.mailgun.org',
        message: message.toString('ascii')
    };

    mailgun.messages().sendMime(dataToSend, function (sendError, body) {
        if (sendError) {
            console.log(sendError);
            return;
        }
    });
});
sjs7007 commented 8 years ago

Send html forms with prefilled data and hidden fields for pausing, resuming and killing.

intput type="hidden" will hide that field

sjs7007 commented 8 years ago

use ejs for dynamic html +

http://stackoverflow.com/questions/9970053/can-express-with-ejs-render-html-to-a-variable-so-i-can-send-as-e-mail

for saving in text form to send

sjs7007 commented 8 years ago

ejs code

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 
    </head>

    <body>

        <h1>S3-Lab-Test</h1>
        <form action="http://localhost:8888/killProcess" enctype="multipart/form-data" method="post">   
        Process ID : <input  type="hidden" name="pid" value= <%= pid %> > <br>
        <input type="submit"  value="kill process" />
        </form>

    </body>
</html>

express code for rendering

var express = require('express'); 
var app = express();
app.set('view engine', 'ejs');

app.get('/', function(req, res){ 
 res.render('killProcess.ejs',{pid: "203"});
 });

app.listen(8888,function() {
    console.log('App listen 8888');
});
sjs7007 commented 8 years ago

ejs code for rendering and sending mail

var domain = 'sandbox2796510b356d4fd5a02c639af3080887.mailgun.org';
var mailgun = require('mailgun-js')({ apiKey: "dummy", domain: domain });
var mailcomposer = require('mailcomposer');
var ejs = require('ejs');

var sendMail = function(data) {
    var mail = mailcomposer({
        from: 'S3 Lab <postmaster@sandbox2796510b356d4fd5a02c639af3080887.mailgun.org>',
        to: 'sjs7007@gmail.com',
        subject: 'Test email subject',
        body: 'Test email text',
        html: data
    });

    mail.build(function(mailBuildError, message) {
        var dataToSend = {
                to: 'sjs7007@gmail.com',
                message: message.toString('ascii')
        };

        mailgun.messages().sendMime(dataToSend, function (sendError, body) {
                if (sendError) {
                        console.log(sendError);
                        return;
                }
        });
    });
}

var fs = require('fs');

fs.readFile('./killProcess.ejs',function(err,ejsTemplate) {
    if(err) {
        console.log(err);
    }
    else {
        ejsTemplate = ejsTemplate.toString();
        console.log(ejsTemplate);
        htmlGen = ejs.render(ejsTemplate,{pid: "405"});
        sendMail(htmlGen);
    }
});
sjs7007 commented 8 years ago

Added all buttons. Gmail on android doesn't allow forms.

https://productforums.google.com/forum/#!topic/docs/MrDT69owdGk