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

SendMail via Parse.Cloud.sendMail() #7089

Closed
3 tasks done
dblythy opened this issue Dec 21, 2020 · 4 comments
Closed
3 tasks done

SendMail via Parse.Cloud.sendMail() #7089

dblythy opened this issue Dec 21, 2020 · 4 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Dec 21, 2020

New Feature / Enhancement Checklist

Current Limitation

I currently use a Mailgun emailAdapter on my Parse Servers. Yet in my cloud code whenever I want to send email, I have to call:

  const api_key = "";
  const domain = "";
  const mailgun = require("mailgun-js")({
    apiKey: api_key,
    domain: domain
    });
  const data = {
    from: "",
    to: obj.get("email"),
    subject: "",
    text: ",
    html: summary
    };
  mailgun.messages().send(data, function(error, body) {});

I could be doing this wrong, idk.

Feature / Enhancement Description

It would be nice to have:

Parse.Cloud.sendEmail(data) and it inherit the sendEmail function from the emailAdapter. It would also support newer developers as they don't have to read their mail providers docs to learn how to send email, as the adapter handles it for them. If no email adapter is specified, throw an error.

@mman
Copy link
Contributor

mman commented Dec 24, 2020

You can already do this easily like this:

const { AppCache } = require('parse-server/lib/cache');

Parse.Cloud.afterLogin(async request => {
  const MailgunAdapter = AppCache.get('INSERT_YOUR_APPID_HERE').userController.adapter;

  const { object: user }  = request;
  const email = user.get('email');

    return MailgunAdapter.send({
      templateName: 'newLoginEmail',
      recipient: email,
      variables: { username: email, date: Date().toString() }
    });
  }
});

@mtrezza
Copy link
Member

mtrezza commented Dec 24, 2020

Thanks for suggesting.

It may be just a simple PR, but it could be a nice convenience method to simply call Parse.Cloud.sendMail({...}) instead of having to reference the mail adapter manually, saving one or two lines of code and reducing complexity for the developer.

@dblythy
Copy link
Member Author

dblythy commented Dec 24, 2020

PR already on the way if you’re keen to review my code again @mtrezza ;)

@mtrezza
Copy link
Member

mtrezza commented Dec 30, 2020

Closed by #7096.

@mtrezza mtrezza closed this as completed Dec 30, 2020
@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

3 participants