Skip to content

Commit

Permalink
added 'reEmailUser(..)' functionality to generate tool, to resend ema…
Browse files Browse the repository at this point in the history
…ils that people have lost
  • Loading branch information
getify committed Jan 7, 2014
1 parent dd612fe commit 86f22b8
Showing 1 changed file with 66 additions and 23 deletions.
89 changes: 66 additions & 23 deletions kickstarter-survey-site/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,59 @@ function setRewardLevelFlags(level,record) {
}
}

function emailUser(userID,userData) {
return ASQ(function(done){
var email_subject = grips.render("email-invite#subject",{
name: userData["Backer Name"]
});
var email_body = grips.render("email-invite#body",{
name: userData["Backer Name"],
email: userData["Email"],
user_id: userID
});

smtpTransport.sendMail({
from: "'You Don't Know JS' Kickstarter <getify+ydkjs@gmail.com>",
to: userData["Email"],
subject: email_subject,
text: email_body
},function(err,res){
if (err) {
done.fail("Error emailing " + userData["Email"] +": " + err);
}
else {
console.log("Email sent: " + userData["Email"]);
done();
}
});
});
}

function reEmailUser(emailAddress) {
var email_hash = sha1(emailAddress);

return getFromDB(
/*key=*/"email:" + email_hash,
/*fields=*/"user_id"
)
.seq(function(emailData){
return getFromDB(
/*key=*/"user:" + emailData.user_id,
/*fields=*/["name","email"]
)
.val(function(userData){
return ASQ.messages(
/*userID=*/emailData.user_id,
/*userData=*/{
"Backer Name": userData.name,
"Email": userData.email
}
);
});
})
.seq(emailUser);
}

function runGeneration() {
getCSVRecords(path.join(__dirname,"csv"))
.seq(function(rewardLevels){
Expand Down Expand Up @@ -182,36 +235,16 @@ function runGeneration() {
var segments = Array.prototype.slice.call(arguments)
.map(function(arg){
return function __segment__(done) {
var email_subject = grips.render("email-invite#subject",{
name: arg[1]["Backer Name"]
});
var email_body = grips.render("email-invite#body",{
name: arg[1]["Backer Name"],
email: arg[1]["Email"],
user_id: arg[0]
});

smtpTransport.sendMail({
from: "'You Don't Know JS' Kickstarter <getify+ydkjs@gmail.com>",
to: arg[1]["Email"],
subject: email_subject,
text: email_body
},function(err,res){
if (err) {
done.fail("Error: " + err);
}
else {
console.log("Email sent: " + arg[1]["Email"]);
done();
}
});
emailUser(arg[0],arg[1])
.pipe(done);
};
});

return ASQ()
.gate.apply(ø,segments)
.val(function(){
DB_store.connection.end();
smtpTransport.close();
console.log("All done");
});
})
Expand Down Expand Up @@ -471,6 +504,16 @@ redis.connect({
DB_store = db;

runGeneration();

/*reEmailUser("..")
.val(function(){
DB_store.connection.end();
smtpTransport.close();
})
.or(function(){
DB_store.connection.end();
smtpTransport.close();
});*/
},
// connection error
function(err){
Expand Down

0 comments on commit 86f22b8

Please sign in to comment.