Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.20 KB | None | 0 0
  1. code: 'EAUTH', response: '454 4.7.0 Too many login attempts, please try again later. p9sm21658988pfe.22 - gsmtp', please Help me
  2.  
  3. router.post('/sendmail', function(req, res) { // sending mail
  4.  
  5. /*
  6. *
  7. * Task : Run Server and fetch multiple emails from DB to send reminder
  8. * Invoke all the email task at once and update DB once the email is sent
  9. */
  10.  
  11. var listofemails = [];
  12. var listofempids = [];
  13. var listofempnames = [];
  14. var empname;
  15. var empid;
  16. var j = -1;
  17. var y = moment().format('YYYY');
  18. var m = moment().subtract(1, 'months').format('MMMM');
  19.  
  20. var dbs = monk('localhost:27017/payroll');
  21. var collection = dbs.get('employee');
  22. collection.find({
  23. $and: [{
  24. "month": m
  25. }, {
  26. "year": y
  27. }]
  28. }, function(e, docs) {
  29.  
  30. if (e) {
  31. console.log(e);
  32. } else {
  33.  
  34. // console.log(docs);
  35.  
  36.  
  37. }
  38. for (var i = 0; i < docs.length; i++) {
  39. listofemails.push(docs[i].emailid);
  40. listofempids.push(docs[i].empid);
  41. listofempnames.push(docs[i].employeename);
  42.  
  43. // console.log(emaillist);
  44.  
  45.  
  46. }
  47.  
  48. // Will store email sent successfully.
  49.  
  50. //var listofemails = [list];
  51.  
  52. var success_email = [];
  53. // Will store email whose sending is failed.
  54. var failure_email = [];
  55.  
  56. var transporter;
  57.  
  58. /* Loading modules done. */
  59.  
  60.  
  61. function massMailer() {
  62. var self = this;
  63. transporter = nodemailer.createTransport({
  64. host: 'smtp.gmail.com',
  65. port: 587,
  66. auth: {
  67. user: 'myhub@aditya.ac.in',
  68. pass: 'Thub@123'
  69. },
  70. tls: {
  71. rejectUnauthorized: false
  72. },
  73. debug: true
  74. });
  75. // Fetch all the emails from database and push it in listofemails
  76. self.invokeOperation();
  77. };
  78.  
  79. /* Invoking email sending operation at once */
  80.  
  81. massMailer.prototype.invokeOperation = function() {
  82. var self = this;
  83. /*async.each(listofempnames,self.SendEname,function(){
  84.  
  85. });
  86. async.each(listofempids,self.SendEmpid,function(){
  87.  
  88. });*/
  89. async.each(listofemails, self.SendEmail, function() {
  90. console.log(success_email);
  91. console.log(failure_email);
  92. });
  93.  
  94.  
  95. }
  96. /*massMailer.prototype.SendEname = function(Ename,callback) {
  97.  
  98. async.waterfall([
  99. function(callback) {
  100.  
  101. },
  102. ],function(){
  103. //When everything is done return back to caller.
  104. callback();
  105. });
  106.  
  107. }
  108. massMailer.prototype.SendEmpid = function(Empids,callback) {
  109. empid=Empids;
  110. async.waterfall([
  111. function(callback) {
  112.  
  113. },
  114. ],function(){
  115. //When everything is done return back to caller.
  116. callback();
  117. });
  118.  
  119. }*/
  120.  
  121. /*
  122. * This function will be called by multiple instance.
  123. * Each instance will contain one email ID
  124. * After successfull email operation, it will be pushed in failed or
  125. success
  126. array.
  127. */
  128.  
  129. massMailer.prototype.SendEmail = function(Email, callback) {
  130. console.log("Sending email to " + Email);
  131. var self = this;
  132. self.status = false;
  133.  
  134. var months = ["January", "February", "March", "April", "May", "June",
  135. "July", "August", "September", "October", "November", "December"
  136. ];
  137.  
  138. var monthInt = new Date().getMonth();
  139. var year = new Date().getFullYear();
  140. var monthString = months[monthInt - 1];
  141.  
  142. var filename = monthString + '-' + year + '-' + listofempids[j + 1] + '.pdf';
  143. var a = monthString + ' ' + year;
  144. // console.log(filename,a);
  145.  
  146. var msg = "<!DOCTYPE html><html><head><meta name='viewport'
  147. content='width=device-width'><meta http-equiv='Content-Type'
  148. content='text/html; charset=UTF-8'><title>Payslip Email</title><style
  149. type='text/css'>@media only screen and (max-width: 800px)
  150. {table[class=body] h1 {font-size: 28px !important;table[class=body]
  151. p,table[class=body] ul,table[class=body] ol,table[class=body]
  152. td,table[class=body] span,table[class=body] a {font-size: 16px !important;
  153. table[class=body] .wrapper,table[class=body] .article {padding: 10px
  154. !important; }table[class=body] .content {padding: 0 !important;
  155. }table[class=body] .container {padding: 0 !important;width: 100%
  156. !important; }table[class=body] .main {border-left-width: 0
  157. !important;border-radius: 0 !important;border-right-width: 0 !important;
  158. }table[class=body] .btn table {width: 100% !important; }table[class=body]
  159. .btn a {width: 100% !important; }table[class=body] .img-responsive
  160. {height: auto !important;max-width: 100% !important;width: auto
  161. !important; }}@media all {.ExternalClass {width: 100%;
  162. }.ExternalClass,.ExternalClass p,.ExternalClass span,.ExternalClass
  163. font,.ExternalClass td,.ExternalClass div {line-height: 100%; }.apple-link
  164. a {color: inherit !important;font-family: inherit !important;font-size:
  165. inherit !important;font-weight: inherit !important;line-height: inherit
  166. !important;text-decoration: none !important; }.btn-primary table td:hover
  167. {background-color: #34495e !important; }.btn-primary a:hover {background-
  168. color: #34495e !important;border-color: #34495e !important; } }.style1
  169. {font-size: 9px}</style></head><body class='' style='background-
  170. color:#f6f6f6;font-family:sans-serif;-webkit-font-
  171. smoothing:antialiased;font-size:14px;line-height:1.4;margin:0;padding:0;-
  172. ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;'><table
  173. border='0' cellpadding='0' cellspacing='0' class='body' style='border-
  174. collapse:separate;mso-table-lspace:0pt;mso-table-rspace:0pt;background-
  175. color:#f6f6f6;width:100%;'><tr><td style='font-family:sans-serif;font-
  176. size:14px;vertical-align:top;'>&nbsp;</td><td class='container'
  177. style='font-family:sans-serif;font-size:14px;vertical-
  178. align:top;display:block;max-width:580px;padding:10px;width:580px;Margin:0
  179. auto !important;'><div class='content' style='box-sizing:border-
  180. box;display:block;Margin:0 auto;max-width:580px;padding:10px;'><!-- START
  181. CENTERED WHITE CONTAINER --><span class='preheader'
  182. style='color:transparent;display:none;height:0;max-height:0;max-
  183. width:0;opacity:0;overflow:hidden;mso-
  184. hide:all;visibility:hidden;width:0;'></span><table class='main'
  185. style='border-collapse:separate;mso-table-lspace:0pt;mso-table-
  186. rspace:0pt;background:#fff;border-radius:3px;width:100%;'><tr><td
  187. class='wrapper' style='font-family:sans-serif;font-size:14px;vertical-
  188. align:top;box-sizing:border-box;padding:20px;'><table border='0'
  189. cellpadding='0' cellspacing='0' style='border-collapse:separate;mso-
  190. table-lspace:0pt;mso-table-rspace:0pt;width:100%;'><tr><td style='font-
  191. family:sans-serif;font-size:14px;vertical-align:top;'><p align='right'
  192. style='font-family:sans-serif;font-size:14px;font-
  193. weight:normal;margin:0;Margin-bottom:15px;'><img
  194. src='http://ecourses.aec.edu.in/thub/images/myhub_aditya.png' width='84'
  195. height='50' alt='AdityaLogo'><p style='font-family:sans-serif;font-
  196. size:14px;font-weight:normal;margin:0;Margin-bottom:15px;'>Hi"+"
  197. "+listofempnames[j+1]+",<p style='font-family:calibri;font-
  198. color:#295890;font-size:14px;font-weight:normal;margin:0;Margin-
  199. bottom:15px;'>Please find your payslip for the month of"+"
  200. "+monthString+" "+year+" "+"attached with the mail.<p>Regards,<br><img
  201. src='http://ecourses.aec.edu.in/thub/images/myhublogo.png' width='84'
  202. height='50' alt='MyHubLogo'><br>Payroll processing system</p><br><p
  203. style='font-family:sans-serif;font-size:10px;font-
  204. weight:normal;margin:0;Margin-bottom:15px;'> Your PDF Payslip is
  205. delivered to your inbox, and you will be able to open the PDF attachment,
  206. only if you have Adobe reader version 7.0.8 and above. If Adobe Reader is
  207. not installed / upgraded in your PC. <a
  208. href='https://acrobat.adobe.com/in/en/acrobat/pdf-reader.html'>click
  209. here</a>.</p><div align='justify'><br></div><p style='font-family:sans-
  210. serif;font-size:10px;font-weight:normal;margin:0;Margin-bottom:15px;'>The
  211. information contained in this electronic message and any attachments to
  212. this message are intended for the exclusive use of the addressee(s) and
  213. may contain proprietary, confidential or privileged information. If you
  214. are not the intended recipient, you should not disseminate, distribute or
  215. copy this e-mail. Please notify the sender immediately and destroy all
  216. copies of this message and any attachments. WARNING: Computer viruses can
  217. be transmitted via email. The recipient should check this email and any
  218. attachments for the presence of viruses. The management accepts no
  219. liability for any damage caused by any virus transmitted by this email.
  220. </p><table border='0' cellpadding='0' cellspacing='0' class='btn btn-
  221. primary' style='border-collapse:separate;mso-table-lspace:0pt;mso-table-
  222. rspace:0pt;box-sizing:border-box;width:100%;'><tbody><tr><td align='left'
  223. style='font-family:sans-serif;font-size:14px;vertical-align:top;padding-
  224. bottom:15px;'><center><table border='0' cellpadding='0' cellspacing='0'
  225. style='border-collapse:separate;mso-table-lspace:0pt;mso-table-
  226. rspace:0pt;width:100%;width:auto;'><tbody><tr><td style='font-
  227. family:sans-serif;font-size:14px;vertical-align:top;background-
  228. color:#ffffff;border-radius:5px;text-align:center;background-color:;'>
  229. </td></tr></tbody></table></center></td></tr></tbody></table><p
  230. style='font-family:sans-serif;font-size:14px;font-
  231. weight:normal;margin:0;Margin-bottom:15px;'></p><p style='font-
  232. family:sans-serif;font-size:11px;font-weight:normal;margin:0;Margin-
  233. bottom:15px;text-align:center;'>Have a Good Day!.</p></td></tr></table>
  234. </td></tr></table><!-- START FOOTER --><div class='footer'
  235. style='clear:both;padding-top:10px;text-align:center;width:100%;'><table
  236. border='0' cellpadding='0' cellspacing='0' style='border-
  237. collapse:separate;mso-table-lspace:0pt;mso-table-
  238. rspace:0pt;width:100%;'><tr><td class='content-block' style='font-
  239. family:sans-serif;font-size:14px;vertical-align:top;color:#999999;font-
  240. size:12px;text-align:center;'><span class='apple-link'
  241. style='color:#999999;font-size:12px;text-align:center;'>Aditya
  242. Educational Institutions,Surampalem,533437</span><br>This email is
  243. system generated, please do not respond to this email.</td></tr><tr><td
  244. class='content-block powered-by' style='font-family:sans-serif;font-
  245. size:14px;vertical-align:top;color:#999999;font-size:12px;text-
  246. align:center;'>Powered by <a href='http://thub.ac.edu.in'
  247. style='color:#3498db;text-decoration:underline;color:#999999;font-
  248. size:12px;text-align:center;text-decoration:none;'>T-HUB team</a>.</td>
  249. </tr></table></div><!-- END FOOTER --><!-- END CENTERED WHITE CONTAINER
  250. --></div></td><td style='font-family:sans-serif;font-size:14px;vertical-
  251. align:top;'>&nbsp;</td></tr></table></body></html>";
  252. // waterfall will go one after another
  253. // So first email will be sent
  254. // Callback will jump us to next function
  255. // in that we will update DB
  256. // Once done that instance is done.
  257. // Once every instance is done final callback will be called.
  258. j++;
  259. async.waterfall([
  260. function(callback) {
  261. var mailOptions = {
  262. from: '"myHUB " <myhub@aditya.ac.in>',
  263. to: Email,
  264. subject: 'Payslip for the month of' + ' ' + ' ' + monthString + ' ' + '
  265. '+year,
  266. text: 'Payslip', // plain text body
  267. html: msg, // html body
  268.  
  269. attachments: [
  270. //{data:msg, alternative:true},
  271. {
  272. path: "C:/users/admin/downloads/" + filename,
  273. type: "application/pdf",
  274. name: filename
  275. }
  276. ]
  277.  
  278. };
  279. transporter.sendMail(mailOptions, function(error, info) {
  280. if (error) {
  281. console.log(error)
  282. failure_email.push(Email);
  283. } else {
  284. self.status = true;
  285. success_email.push(Email);
  286. }
  287. callback(null, self.status, Email);
  288. });
  289. },
  290. function(statusCode, Email, callback) {
  291. console.log("Mail sent for " + Email + "With " + statusCode);
  292.  
  293. callback();
  294. }
  295.  
  296. ], //
  297.  
  298. function(j) {
  299. //When everything is done return back to caller.
  300. if (j == 6) {
  301. transporter.close();
  302. } else {
  303. callback();
  304. }
  305. });
  306. // res.json("hai");
  307.  
  308. }
  309.  
  310. new massMailer(); //lets begin
  311. });
  312. });
  313.  
  314. transporter = nodemailer.createTransport({
  315. host: 'smtp.gmail.com',
  316. port: 465,
  317. pool : true,
  318. auth: {
  319. user: 'myhub@aditya.ac.in',
  320. pass: 'Thub@123'
  321. },
  322. tls: {
  323. rejectUnauthorized: false
  324. },
  325. debug: true
  326. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement