daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 374 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dig TXT default._domainkey.example.com
  2.    
  3. ; <<>> DiG 9.8.3-P1 <<>> TXT default._domainkey.mydomain.com
  4. ;; global options: +cmd
  5. ;; Got answer:
  6. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28927
  7. ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
  8.  
  9. ;; QUESTION SECTION:
  10. ;default._domainkey.mydomain.com. IN    TXT
  11.  
  12. ;; ANSWER SECTION:
  13. default._domainkey.mydomain.com. 3554 IN TXT    "k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmwCHK6Szd9ObPoD9I4JkdB9+W7a/IzGKnntAbWnHitMxQyl4TsmofRm+RZDS/Ije99opzmjLBeaCiiNXYs6nvhaVR4lrN9IFpmaJ5yuyicmE9HCDM99qlPUUzgk4l3YAGVSNK83FS7UNc5r0Ymh1bWKKB6FFwqgjVAzP6yJ7Bst0C88Wko0UHSJqeg3Y4mfeys9p6yyro4" "HnFJ+UQGYtwGD11z5+MdHI9D5eIa1TC7t0VSRYll94n4VHZI43uGO+jk3tm/LCMaYaksEiMD55rLUg78VAhh0pDsNPowbeXxcBYITqv9oMn7tNZQQKmXRU5G/WwsBpi9wrJuja7vl22wIDAQAB"
  14.  
  15. ;; Query time: 0 msec
  16. ;; SERVER: 192.168.1.1#53(192.168.1.1)
  17. ;; WHEN: Tue Oct 17 13:53:10 2017
  18. ;; MSG SIZE  rcvd: 464
  19.    
  20. var fs = require('fs');
  21. var nodemailer = require('nodemailer');
  22. var EmailTemplate = require('email-templates').EmailTemplate
  23. var path = require('path')
  24.  
  25. // config of nodemailer
  26. var poolConfig = {
  27.     pool: true
  28.     , host: 'mail.example.com'
  29.     , port: 25
  30.     , secure: false // use SSL
  31.     , auth: {
  32.             user: 'info@example.com',
  33.             pass: 'mypassword'
  34.     }, tls: {
  35.             rejectUnauthorized: false
  36.     }, dkim: {
  37.             domainName: 'example.com'
  38.             , keySelektor: 'default'
  39.             , privateKey: fs.readFileSync('./certificates/dkim/dkim.pem', "utf8")
  40.             , cacheDir: '/tmp'
  41.             , cacheTreshold: 100 * 1024
  42.     }
  43. };
  44.  
  45. // use config to generate a transporter
  46. var transporter = nodemailer.createTransport(poolConfig);
  47.  
  48. // the email and its content as json
  49. var user = {email: "info@example.com"};
  50. var message = {
  51.     template : "contactform"
  52.     , subject : "Message from Simon"
  53.     , pageData : {formdata: {salutation : "salutation", firstname: "firstname", lastname : "lastname", phone : "phone", email: "email", subject : "subject", text : "text" }}
  54. };
  55.  
  56. // send the email
  57. if(user && user.email) {
  58.     if(message.template && message.subject && message.pageData ) {
  59.         var path_email = path.join(__dirname, 'templates', message.template)
  60.         var template_email = new EmailTemplate(path_email)
  61.  
  62.         message.pageData.base_url = "https://example.com";
  63.  
  64.         console.log(message.pageData);
  65.  
  66.         template_email.render(message.pageData, function (err, result) {
  67.             if (err) {
  68.                 return console.error(err)
  69.             }
  70.             // actual sending of the email
  71.             transporter.sendMail({
  72.                 from: "info@example.com", // sender address
  73.                 to: user.email, // list of receivers
  74.                 subject: message.subject, // Subject line
  75.                 html: result.html,
  76.                 text: result.text.replace(/</p>/g,'n').replace(/</?w+((s+w+(s*=s*(?:".*?"|'.*?'|[^'">s]+))?)+s*|s*)/?>/g,'')
  77.             }, function (err, responseStatus) {
  78.                 if (err) {
  79.                     return console.error(err)
  80.                 }
  81.                 console.log("email send to " + user.email);
  82.             })
  83.         })
  84.     } else {
  85.         console.log("Error no template, subject or pageData", null);
  86.     }
  87. } else {
  88.     console.log("Error no user or email", null);
  89. }
  90.  
  91. // create a hello world nodejs server to wait until email has send...
  92. var express = require('express');
  93. var app = express();
  94. app.listen(3000, function () {
  95.   console.log('Example app listening on port 3000. Waiting for email to be send...');
  96. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top