Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How exactly do you use sails to send mails? #6833

Open
kanlanc opened this issue Aug 5, 2019 · 6 comments
Open

How exactly do you use sails to send mails? #6833

kanlanc opened this issue Aug 5, 2019 · 6 comments

Comments

@kanlanc
Copy link

kanlanc commented Aug 5, 2019

I have used the template that comes when sails new is used, I originally thought that changing the config of verifyEmail would do what I need after adding the mailgun creds but this is not happening, this is my package.json

{
  "name": "happyfitt",
  "private": true,
  "version": "1.1.7",
  "description": "Happyfitt made using sails and react",
  "keywords": [],
  "dependencies": {
    "@sailshq/connect-redis": "^3.2.1",
    "@sailshq/lodash": "^3.10.3",
    "@sailshq/socket.io-redis": "^5.2.0",
    "moment": "^2.24.0",
    "qr-image": "^3.2.0",
    "sails": "^1.1.0",
    "sails-hook-apianalytics": "^2.0.3",
    "sails-hook-organics": "^0.15.0",
    "sails-hook-orm": "^2.1.1",
    "sails-hook-sockets": "^1.5.5",
    "sails-mongo": "^1.0.1"
  },
  "devDependencies": {
    "@sailshq/eslint": "^4.19.3",
    "@sailshq/htmlhint": "^0.9.16",
    "@sailshq/lesshint": "^4.6.6",
    "chai": "^4.2.0",
    "grunt": "1.0.1",
    "istanbul": "^0.4.5",
    "mocha": "^6.1.4",
    "sails-hook-fixtures": "^1.0.1",
    "sails-hook-grunt": "^3.1.0",
    "supertest": "^4.0.2"
  },
  "scripts": {
    "start": "NODE_ENV=production node app.js",
    "test-eslint": "npm run lint -s && echo 'Done.'",
    "lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔  Your .js files look so good.' ",
    "debug": "node debug app.js",
    "test": "mocha test",
    "coverage": "istanbul cover _mocha -- -t 10000 -R spec tests/boostrap.test.js test/**/*.test.js",
    "deploy": "echo 'This script assumes a dead-simple, opinionated setup on Heroku.' && echo 'But, of course, you can deploy your app anywhere you like.' && echo '(Node.js/Sails.js apps are supported on all modern hosting platforms.)' && echo && echo 'Warning: Specifically, this script assumes you are on the master branch, and that your app can be deployed simply by force-pushing on top of the *deploy* branch.  It will also temporarily use a local *predeploy* branch for preparing assets, that it will delete after it finishes.  Please make sure there is nothing you care about on either of these two branches!!!' && echo '' && echo '' && echo 'Preparing to deploy...' && echo '--' && git status && echo '' && echo '--' && echo 'I hope you are on the master branch and have everything committed/pulled/pushed and are completely up to date and stuff.' && echo '********************************************'  && echo '** IF NOT THEN PLEASE PRESS <CTRL+C> NOW! **' && echo '********************************************' && echo 'Press CTRL+C to cancel.' && echo '(you have five seconds)' && sleep 1 && echo '...4' && sleep 1 && echo '...3' && sleep 1 && echo '...2' && sleep 1 && echo '...1' && sleep 1  && echo '' && echo 'Alright, here we go.  No turning back now!' && echo 'Trying to switch to master branch...' && git checkout master && echo && echo 'OK.  Now wiping node_modules/ and running npm install...' && rm -rf node_modules && rm -rf package-lock.json && npm install && (git add package-lock.json && git commit -am 'AUTOMATED COMMIT: Did fresh npm install before deploying, and it caused something relevant (probably the package-lock.json file) to change!  This commit tracks that change.' || true) && echo 'Deploying as version:' && npm version patch && echo '' && git push origin master && git push --tags && (git branch -D predeploy > /dev/null 2>&1 || true) && git checkout -b predeploy && (echo 'Now building+minifying assets for production...' && echo '(Hang tight, this could take a while.)' && echo && node node_modules/grunt/bin/grunt buildProd || (echo && echo '------------------------------------------' && echo 'IMPORTANT!  IMPORTANT!  IMPORTANT!' && echo 'ERROR: Could not compile assets for production!' && echo && echo 'Attempting to recover automatically by stashing, ' && echo 'switching back to the master branch, and then ' && echo 'deleting the predeploy branch... ' && echo && echo 'After this, please fix the issues logged above' && echo 'and push that up.  Then, try deploying again.' && echo '------------------------------------------' && echo && echo 'Staging, deleting the predeploy branch, and switching back to master...' && git stash && git checkout master && git branch -D predeploy && false)) && mv www .www && git add .www && node -e 'sailsrc = JSON.parse(require(\"fs\").readFileSync(\"./.sailsrc\", \"utf8\"));  if (sailsrc.paths&&sailsrc.paths.public !== undefined || sailsrc.hooks&&sailsrc.hooks.grunt !== undefined) { throw new Error(\"Cannot complete deployment script: .sailsrc file has conflicting contents!  Please throw away this midway-complete deployment, switch back to your original branch (master), remove the conflicting stuff from .sailsrc, then commit and push that up.\"); }  sailsrc.paths = sailsrc.paths || {};  sailsrc.paths.public = \"./.www\";   sailsrc.hooks = sailsrc.hooks || {};  sailsrc.hooks.grunt = false;  require(\"fs\").writeFileSync(\"./.sailsrc\", JSON.stringify(sailsrc))' && git commit -am 'AUTOMATED COMMIT: Automatically bundling compiled assets as part of deploy, updating the EJS layout and .sailsrc file accordingly.' && git push origin predeploy && git checkout master && git push origin +predeploy:deploy && git push --tags && git branch -D predeploy && git push origin :predeploy && echo '' && echo '--' && echo 'OK, done.  It should be live momentarily on your staging environment.' && echo '(if you get impatient, check the Heroku dashboard for status)' && echo && echo 'Staging environment:' && echo ' 🌐–•  https://staging.example.com' && echo '       (hold ⌘ and click to open links in the terminal)' && echo && echo 'Please review that to make sure it looks good.' && echo 'When you are ready to go to production, visit your pipeline on Heroku and press the PROMOTE TO PRODUCTION button.'"
  },
  "main": "app.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/highskillzz/Happyfitt.git"
  },
  "author": "Vikranth Kanumuru",
  "license": "",
  "engines": {
    "node": "^10.15"
  }
}


and I also don't see mailgun anywhere. How do I do this exactly?

Thank you

@sailsbot
Copy link

sailsbot commented Aug 5, 2019

@highskillzz Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. (Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)
  • tell us why this issue is important to you and your team. What are you trying to accomplish? (Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. (Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. (Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. (Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@kanlanc
Copy link
Author

kanlanc commented Aug 8, 2019

Anyone?

@navicstein
Copy link

You can optionally create a helper and integrate nodemailer

// am using gmail transports in this example
module.exports = {
  friendlyName: "Send email",

  description: "Sails helper to send emails",

  inputs: {
    to: {
      type: "string",
      required: true
    },
    subject: {
      type: "string",
      required: true
    },
    text: {
      type: "string",
      required: true
    }
  },
  exits: {
    success: {
      description: "All done."
    }
  },
  fn: async function(inputs) {
    var nodemailer = require("nodemailer");
    var transporter = nodemailer.createTransport({
      service: "gmail",
      auth: {
        user: "example@gmail.com",
        pass: "password"
      }
    });

    var data = {
      from: "demo <no-reply@demo.com>",
      to: inputs.to,
      subject: inputs.subject,
      text: inputs.text
    };
    sails.log.debug(data);
    transporter.sendMail(data, function(error, info) {
      error
        ? sails.log.error(error)
        : sails.log.info("Email sent: " + info.response);
    });
  }
};

or checkout https://github.com/mikermcneil/ration/blob/master/api/helpers/send-template-email.js

@nahanil
Copy link

nahanil commented Aug 10, 2019

@highskillzz You appear to have sails-hook-organics installed which includes some basic mailgun stuff.

The "Web App" starter project should include some basic email functionality if you add your mailgun config. The Ration app also has a few examples of how to do it (using the sendTemplateEmail helper method to hide away some of the messiness of loading email templates).

https://github.com/mikermcneil/ration/blob/master/api/controllers/entrance/signup.js#L106
https://github.com/mikermcneil/ration/blob/master/api/controllers/deliver-contact-form-message.js#L63

@kanlanc
Copy link
Author

kanlanc commented Aug 12, 2019

Please answer this question I have, I have used zoho for making company emails and used my domain records over there. But, now I have to validate emails I get from users and mailgun seems to do that(from what I understand), but it is also asking domain details and to put records over there. Is there a way I can verify emails but not change zoho since it is providing company emails for free

@johnabrams7
Copy link
Contributor

johnabrams7 commented Aug 26, 2019

@highskillzz Hi! I think that Mailgun gives you up to 12,000 emails per month free. The Sails web app template also provides send template email, which is designed to be maximally customizable.

See: helpers/send-template-email.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants