{"action":"created","issue":{"url":"https://api.github.com/repos/koajs/koa/issues/433","labels_url":"https://api.github.com/repos/koajs/koa/issues/433/labels{/name}","comments_url":"https://api.github.com/repos/koajs/koa/issues/433/comments","events_url":"https://api.github.com/repos/koajs/koa/issues/433/events","html_url":"https://github.com/koajs/koa/issues/433","id":67992893,"number":433,"title":"nodemailer in koajs","user":{"login":"petitspois","id":9461149,"avatar_url":"https://avatars.githubusercontent.com/u/9461149?v=3","gravatar_id":"","url":"https://api.github.com/users/petitspois","html_url":"https://github.com/petitspois","followers_url":"https://api.github.com/users/petitspois/followers","following_url":"https://api.github.com/users/petitspois/following{/other_user}","gists_url":"https://api.github.com/users/petitspois/gists{/gist_id}","starred_url":"https://api.github.com/users/petitspois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petitspois/subscriptions","organizations_url":"https://api.github.com/users/petitspois/orgs","repos_url":"https://api.github.com/users/petitspois/repos","events_url":"https://api.github.com/users/petitspois/events{/privacy}","received_events_url":"https://api.github.com/users/petitspois/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-13T02:59:06Z","updated_at":"2015-04-13T20:18:31Z","closed_at":"2015-04-13T20:18:31Z","body":"//smtp.js\r\n```js\r\nvar cSmtp = require('../server/config').smtp,\r\n\r\n    nodemailer = require(\"nodemailer\"),\r\n\r\n    smtpTransport = require('nodemailer-smtp-transport');\r\n\r\n\r\nmodule.exports = function (mailOptions) {\r\n\r\n    cSmtp.secure = true;\r\n    cSmtp.debug = true;\r\n    var transporter = nodemailer.createTransport(smtpTransport(cSmtp));\r\n\r\n    mailOptions && (mailOptions.sender = cSmtp.host);\r\n\r\n    mailOptions && (mailOptions.subject = '[通知]Docs.ren提醒邮件');\r\n\r\n    var smtp = new Promise(function (resolve, reject) {\r\n        transporter.sendMail(mailOptions, function (err, info) {\r\n            if (err) {\r\n                reject(err);\r\n            } else {\r\n                resolve(info);\r\n            }\r\n        });\r\n    });\r\n\r\n    return smtp;\r\n\r\n}\r\n```\r\n//Calling\r\n```js\r\n\r\n//failure prompted 500????\r\n//当用yield ,在reject的时候会报500错误，如何解决\r\nvar sendMail = yield smtpMail({to: email, html: yield ctx.render('smtp', content)});\r\n            console.log(sendMail)\r\n\r\n//notes block, this.body not executed\r\n//当用这种方法时，this.body 不会执行，直接404\r\n                //smtpMail({\r\n                //    to: email,\r\n                //    html: yield ctx.render('smtp', content)\r\n                //}).then(function(){\r\n                //    console.log(1)\r\n                //    ctx.session.pwdKey = content.key;\r\n                //    ctx.session.sendemail = content.email;\r\n                //    ctx.body = {\r\n                //        msg:'邮件发送成功，请尽快查收，更改密码',\r\n                //        status:1\r\n                //    }\r\n                //    return;\r\n                //},function(){\r\n                //    console.log(2)\r\n                //    ctx.body = {\r\n                //        msg:'邮件发送失败，检查网络并重试',\r\n                //        status:0\r\n                //    }\r\n                //});\r\n```"},"comment":{"url":"https://api.github.com/repos/koajs/koa/issues/comments/92486150","html_url":"https://github.com/koajs/koa/issues/433#issuecomment-92486150","issue_url":"https://api.github.com/repos/koajs/koa/issues/433","id":92486150,"user":{"login":"tj","id":25254,"avatar_url":"https://avatars.githubusercontent.com/u/25254?v=3","gravatar_id":"","url":"https://api.github.com/users/tj","html_url":"https://github.com/tj","followers_url":"https://api.github.com/users/tj/followers","following_url":"https://api.github.com/users/tj/following{/other_user}","gists_url":"https://api.github.com/users/tj/gists{/gist_id}","starred_url":"https://api.github.com/users/tj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tj/subscriptions","organizations_url":"https://api.github.com/users/tj/orgs","repos_url":"https://api.github.com/users/tj/repos","events_url":"https://api.github.com/users/tj/events{/privacy}","received_events_url":"https://api.github.com/users/tj/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T20:18:31Z","updated_at":"2015-04-13T20:18:31Z","body":"More of a mailing list / IRC question!"}}