Permalink
Browse files

Last version

  • Loading branch information...
1 parent 684056a commit a16f9a8eb763d772fd8dff1956b737135058daf5 @kuryaki committed Nov 9, 2012
Showing with 91 additions and 35 deletions.
  1. +4 −0 app.js
  2. +0 −31 mail.js
  3. BIN nyan.gif
  4. +50 −3 routes/index.js
  5. +10 −1 views/index.ejs
  6. +27 −0 views/mail.ejs
View
4 app.js
@@ -29,6 +29,10 @@ app.configure('development', function(){
app.get('/', routes.index);
+app.post('/', routes.transport);
+
+app.post('/email', routes.send_email);
+
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
View
31 mail.js
@@ -1,31 +0,0 @@
-var nodemailer = require("nodemailer");
-
-// create reusable transport method (opens pool of SMTP connections)
-var smtpTransport = nodemailer.createTransport("SMTP",{
- service: "Gmail",
- auth: {
- user: "david.roncancio@gmail.com",
- pass: "acbfgvalhreksubn" //Application specific password
- }
-});
-
-// setup e-mail data with unicode symbols
-var mailOptions = {
- from: "David Roncancio ✔ <david.roncancio@gmail.com>", // sender address
- to: "david@codetag.me, david@roncancio.me", // list of receivers
- subject: "Hello ✔", // Subject line
- text: "Hello world ✔", // plaintext body
- html: "<b>Hello world ✔</b>" // html body
-};
-
-// send mail with defined transport object
-smtpTransport.sendMail(mailOptions, function(error, response){
- if(error){
- console.log(error);
- }else{
- console.log("Message sent: " + response.message);
- }
-
- // if you don't want to use this transport object anymore, uncomment following line
- //smtpTransport.close(); // shut down the connection pool, no more messages
-});
View
BIN nyan.gif
Deleted file not rendered
View
@@ -1,8 +1,55 @@
+var nodemailer = require("nodemailer");
-/*
- * GET home page.
- */
+var smtpTransport = '';
exports.index = function(req, res){
res.render('index', { title: 'Mass Personal Mailer' });
+};
+
+exports.transport = function(req, res){
+
+ smtpTransport = nodemailer.createTransport("SMTP",{
+ service: "Gmail",
+ auth: {
+ name: req.body.name,
+ user: req.body.auth_user,
+ pass: req.body.auth_password //Application specific password
+ }
+ });
+
+ res.render('mail', { title: 'Mass Personal Mailer' });
+};
+
+exports.send_email = function(req, res){
+
+ var email_data = JSON.parse(req.body.json_body);
+
+ email_data.forEach(function(element){
+
+ var email_body = req.body.email_body;
+ email_body = email_body.replace("|name|", element.name); //replace for all
+ email_subject = req.body.subject.replace("|name|", element.name);
+
+ var mailOptions = {
+ from: smtpTransport.options.auth.name + "<" + smtpTransport.options.auth.user + ">", // sender address
+ to: element.email, // list of receivers
+ subject: email_subject, // Subject line
+ text: email_body + '\n\n\n' +req.body.signature // plaintext body
+ };
+
+ // send mail with defined transport object
+ smtpTransport.sendMail(mailOptions, function(error, response){
+ if(error){
+ console.log(error);
+ res.send(error);
+ }else{
+ console.log(response.message);
+ res.send("Message sent: " + response.message);
+ }
+ // if you don't want to use this transport object anymore, uncomment following line
+ //smtpTransport.close(); // shut down the connection pool, no more messages
+ });
+ });
+
+
};
View
@@ -7,9 +7,18 @@
<body>
<h1><%= title %></h1>
<p>Please add your gmail account information</p>
- <form action="">
+ <form action="/" method="POST">
+
+ <label for="name">Your Name</label>
+ <input type="text" name="name" id="name" placeholder="ex. David Roncancio">
+
<label for="auth_user">Gmail account</label>
<input type="text" name="auth_user" id="auth_user" placeholder="ex. david.roncancio@gmail.com">
+
+ <label for="auth_password">Gmail Password (or <a href="http://support.google.com/accounts/bin/answer.py?hl=es&answer=185833">application specific password</a>)</label>
+
+ <input type="text" name="auth_password" id="auth_password" placeholder="myAwesomePassword">
+ <input type="submit" value="Authenticate">
</form>
</body>
</html>
View
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= title %></title>
+ <link rel='stylesheet' href='/components/bootstrap/bootstrap/css/bootstrap.css' />
+ </head>
+ <body>
+ <h1><%= title %></h1>
+ <p>Please add your email information</p>
+ <form action="/email" method="POST">
+
+ <label for="json_body">Add your data for the email in JSON format</label>
+ <textarea name="json_body" id="json_body" cols="30" rows="10" placeholder="ex. [{'name':'Tomas','email':'tordonez01@gmail.com'}, {'name':'Alejandro','email':'alejo8591@gmail.com'}"></textarea>
+
+ <label for="subject">Add the subject for the email</label>
+ <input type="text" name="subject" id="subject" placeholder="ex. Codetag contact me now!">
+
+ <label for="email_body">Add the body of your email</label>
+ <textarea name="email_body" id="email_body" cols="30" rows="10" placeholder="ex. Hello |name| nice to meet you last weekend"></textarea>
+
+ <label for="signature">Add the signature of your email</label>
+ <textarea name="signature" id="signature" cols="30" rows="10" placeholder="ex. Hope to see you soon - David"></textarea>
+
+ <input type="submit" value="Send">
+ </form>
+ </body>
+</html>

0 comments on commit a16f9a8

Please sign in to comment.