Пример #1
0
blogContent.read(function(err,blogPosts)
{
 
  	blogPosts.forEach(function(post)
  	{
  
  // CHECK IF POST IS 7 Days old or Less. If it is, put the post object in the array.
  	console.log(post.published);
  	postTime = post.published.split('-');
  	postTimeYear = postTime[0];
  	postTimeMonth = postTime[1];
  	postTimeDay = postTime[2].split('T')[0];
  	postTime = ((postTimeYear - 1970) * 31556952000) + ((postTimeMonth-1) * 2629740000) + ((postTimeDay-1) * 86400000)
  	time = new Date();
  	console.log(postTime);
  	console.log(time.getTime());

  	//if(time - postTime <= 604800000)
  	if(time - postTime <= 2630000000)
  	{
  		//console.log(post);
  		latestPosts.push(post);
  	}
  
 
  	});

	var csvData = csvParse(csvFile);

	csvData.forEach(function(row)
	{
		firstName = row["firstName"];
		numMonthsSinceContact = row["monthsSinceContact"];
		copyTemplate = emailTemplate;
		var customizedTemplate = ejs.render(copyTemplate, 
			{ 
			  firstName: firstName,  
			  monthsSinceContact: numMonthsSinceContact, 
			  latestPosts: latestPosts 
			});
		sendEmail(row["firstName"] + " " + row["lastName"], row["emailAddress"], "Jordan Landau", "*****@*****.**", "j1ands.github.io Latest Blog Posts", customizedTemplate);
	//console.log(customizedTemplate);
	/*
	templateCopy = emailTemplate;
	templateCopy = templateCopy.replace(/FIRST_NAME/gi, firstName).replace(/NUM_MONTHS_SINCE_CONTACT/gi, numMonthsSinceContact);
	*/
	//console.log(templateCopy);
	});
});
Пример #2
0
var from_name    = "Colin VanLang";
var from_email   = "*****@*****.**";
var subject_name = "Catching up! (Hexo Mailer)";


//var email_template_html = fs.readFileSync("email_template.html", "utf8");
var email_template_ejs = fs.readFileSync('email_template.ejs', 'utf8');
var posts = [];

// --- Read xml file and create email templates --- //
blogContent.read(function(err, blogPosts) {
	var now = Date.now();

	// get posts only posted in last 7 days
	blogPosts.forEach(function(post) {
		var post_date = new Date(post.published).getTime();
		if (dayDifference(now, post_date) < 7) {
			posts.push(post);
		}
	});
	makeEmail();
});


// --- Function for sending emails --- //
function sendEmail(to_name, to_email, from_name, from_email, subject, message_html) {
	var message = {
		"html": message_html,
		"subject": subject,
		"from_email": from_email,
		"from_name": from_name,
		"to": [{
blogContent.read(function(err,blogPosts){
 
    blogPosts.forEach(function(post){
       
      var current_date = new Date(); 
      var post_dates = new Date(post.published)

       if((current_date - post_dates) < 604800000){
        latestPosts.push(post); 
       }
    })



      friendList = csvParse(csvFile);

    friendList.forEach(function(row){

      
        firstName = row["firstName"];
        monthsSinceContact = row["monthsSinceContact"];


        customizedTemplate = ejs.render(emailTemplate, 
                        { firstName: firstName,  
                          monthsSinceContact: monthsSinceContact, 
                          latestPosts: latestPosts
        });

sendEmail(firstName, '*****@*****.**', 'Sender', '*****@*****.**', 'Hello', customizedTemplate)
        
    })
})