Skip to content

Instantly share code, notes, and snippets.

@clonn
Created April 13, 2013 00:24
Show Gist options
  • Save clonn/5376219 to your computer and use it in GitHub Desktop.
Save clonn/5376219 to your computer and use it in GitHub Desktop.
Node.js, Send mail by Gmail. it is a simple code in Coffee Script, a full content for Node.js Taiwan Community contributor.
nodemailer = require 'nodemailer'
fs = require 'fs'
_sendMail = (email, code) ->
contentHtml = [
"親愛的 Node.js 台灣社群朋友,"
"<p>"
"由於你的支持,社群活動才能夠得以持續進行,因此特別送上 JSDC 邀請碼,"
"<br/>"
"<br/>"
" JSDC 邀請碼:"
code
"<br/>"
"<br/>"
"煩請至以下連結進行登記報名"
"<br/>"
" <a href='http://registrano.com/events/jsdc2013'>http://registrano.com/events/jsdc2013</a>"
"<br/>"
"</p>"
"<b>特別注意:</b>"
"<br/>"
" JSDC 邀請碼請於 4/19 之前使用完畢,逾期後將取消此邀請碼"
"<p>"
"特此感謝,如有任何問題歡迎聯繫 [email protected]"
"</p>"
"---"
"<p>"
"Node.js Taiwan: http://nodejs.tw"
"<br/>"
"Node.js Book: http://book.nodejs.tw"
"<br/>"
"Node.js Github: https://github.com/nodejs-tw"
"<br/>"
"Node.js Facebook Group: https://www.facebook.com/groups/node.js.tw"
"</p>"
].join('')
mailOptions = {
from: "Node.js Taiwan Contact<[email protected]>",
to: email,
subject: "[邀請] JSDC 社群邀請票",
text: "感謝你今年的協助,明年請繼續支持\n 請持續支持此活動 \n 邀請碼為:" + 'abc123',
html: contentHtml
}
smtpTransport.sendMail mailOptions, (error, response) ->
if(error)
console.log(error);
else
console.log("Message sent: " + response.message);
# Get invitor from a JSON file
_invitor = JSON.parse(fs.readFileSync './PATH/data.json')
smtpTransport = nodemailer.createTransport "SMTP", {
service: "Gmail",
auth: {
user: "email account",
pass: "email pwd"
}
}
for user in _invitor
_sendMail(user['email'], user['Invitation Code'])
console.log user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment