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

Sendgrid Cloud Code Module #554

Closed
dcdspace opened this issue Feb 21, 2016 · 13 comments
Closed

Sendgrid Cloud Code Module #554

dcdspace opened this issue Feb 21, 2016 · 13 comments

Comments

@dcdspace
Copy link

Since Cloud Code doesn't support modules anymore, how can I still use an email service like Sendgrid to send transactional email? Right now I am using its cloud code module, but that does not work in Parse Server. Thanks for the help.

@flovilmart
Copy link
Contributor

@zeluspudding
Copy link

Dylan,
Were you ever able to solve your sendgrid (cloud module not supported) problem? I'm currently managing my cloud code transition and am also feeling a little lost.

@dcdspace
Copy link
Author

dcdspace commented Mar 4, 2016

Yes, I was.

  1. In your package.json file, add the dependency to the Sendgrid npm module:
    "sendgrid": "^1.9.2"
  2. Re-write your cloud code function to follow the new Sendgrid module syntax (slightly different than old unsupported Cloud Code module) https://github.com/sendgrid/sendgrid-nodejs https://www.npmjs.com/package/sendgrid

Note that instead of initializing Sendgrid with your username and password, I recommend you make an API key from the dashboard and use that instead.

Should work from there, lmk how it goes.

@zeluspudding
Copy link

Thank you @dcdspace. I've since been able to require sendgrid in my projects although that didn't seem to help for sending password reset messages. I see you ran into a similar problem in issue #275. I've setup the parse-server-sendgrid-adapter (#971) to basic success - that is, I can send reset messages but the reset link doesn't work and I get "undefined" fields as shown below:

sendgridtest1

Have you been able to successfully send password resets?

EDIT **
Looks like my app name and something else (for the reset link's root) aren't specified. Any tips for how to do that?

@dcdspace
Copy link
Author

No @zeluspudding I've only been using Sendgrid with custom templates for transactional email such as for welcome messages and in addition to push notifications for friend requests. I would however love to use my custom templates for a password reset/email verification email, so it would be great if we could directly access the reset link, and be allowed to customize the reset page.

I'm also not using the parse-server-sendgrid-adapter, but I assume it works the same as the sendgrid npm module I'm using? Also where did you find the documentation on how to use the password reset? Thanks.

@zeluspudding
Copy link

@dcdspace, It appears "adapter" is synonymous with "wrapper" as parse-server-sendgrid-adapter's only dependency is sendgrid. @carmenlau wrote it and likely has more info for the both of us for getting setup correctly (I just included it in my express server initialization as shown here and got the gnarled output attached above). Any advice to get us setup with working reset password links @carmenlau? Shall we continue this conversation at #971?

@zeluspudding
Copy link

After a little more poking around I've come across this - gaze your eyes upon the following:


passwordreset


So the fields pointed out by the number 1 in Pane A are indeed set by the appName argument when initializing ParseServer in the index.js. If you take a look at that source you can see that appName is the third argument to the ParseServer function declaration. Down at the bottom of the argument list are emailAdapter, publicServerURL , and customPages. In order to get password reset emails sent via SendGrid you'll have to set emailAdapter: SendGridAdapter as shown here. Now the portion of the reset URL denoted by the number 2 comes from setting publicServerURL. Following the reset URL takes me to Pane B, then entering my information takes me to Pane C without any sort of confirmation email. Unfortunately, when I try to use my reset password in my client, the client refuses to accept the changed password - I imagine it's not really being set. So here are my questions @carmenlau (or anyone): 1) Do you have any idea why password reset isn't actually resetting passwords? 2) Do you know how I can get rid of the supposed image in the reset email (identified by the orange rectangle)? or better yet 3) can you share how one is supposed to configure custom email templates using the customPages, invalidLink, verifyEmailSuccess, choosePassword, and passwordResetSuccess arguments? Any help would be most appreciated.

@tanzeelrana
Copy link

Hey guys

I have followed the digital oceans guideline to migrate my application from this link :
https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04

now my application uses sendgrid to send very basic text emails. I have tested my cloud code without sendgrid and it works fine.

For my cloud code file it looks something like this :
documents_ parse_pacecourier___ ssh_root_159_203_35_195 _242x42

now whenever I try to run this sendMail function through postman I get an internal server error :
postman

If I click the send button multiple times I sometimes get a 502 Bad Gateway error :
postman_and_sendgrid_cloud_code_module_ _issue__554_ _parseplatform_parse-server_and_new_tab

Now I figured that its the sendgrid that is throwing this error so I tried to install sendgrid on my droplet.

I logged in as parse user

sudo su parse

and created a package.json and added the following to it

{ "dependencies": { "sendgrid": "2.0.0" } }

i still get the same error message. I tried to install sendgripd globally as root on the droplet as well but it did not help my cloud code run

npm install -g sendgrid

I have looked around the internet and haven't found anything as close as this thread to my problem so if any of you guys know how I can fix this I will be greateful as this is the only step left for my application migration.

Cheers,
Tanzeel

@drew-gross
Copy link
Contributor

Can you enable verbose logging in your server, trigger the error, and post a new issue with the output?

@tanzeelrana
Copy link

I'm sorry but Im not sure where I can find the log file.

I have a file ecosystem.json which has parse-wrapper information. Is that the file where I should add VERBOSE = 1 ?

I did a parse-server command in my droplet command-line saw this in the output :
documents_ _root_pacecourier____ _ssh_root_159_203_35_195_ _226x52

So I went to my ecosystem.json file and edited it and now it loks something like this (did I set the verbose correctly ? or do I have to set it like VERBOSE=1 and what about the quotes ):

documents_ _root_pacecourier___home_parse_ _ssh_root_159_203_35_195_ _226x52

I ran the following command

pm2 restart ecosystem.json

and I guess it restarted my parse-wrapper

documents_ _parse_pacecourier____ _ssh_root_159_203_35_195_ _226x52

I can not find the log files for the parse-server on my droplet. Do you know the exact location for the log file ? I tried to look around and found nginx log files under /var/log/nginx/error.log. Since I am using nginx according to Digital Ocean's tutorial, I thought that might also help. This is what I saw in its error logs :

2016/05/11 11:34:29 [error] 18128#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 24.37.6.210, server: test.pacecouriers.com, request: "POST /parse/functions/sendMail HTTP/1.1", upstream: "http://127.0.0.1:1337/parse/functions/sendMail", host: "test.pacecouriers.com"

Thanks 😄

@tanzeelrana
Copy link

So I looked up at pm2 and to see real-time logs the command is

pm2 logs

at first when I ran the command I saw some errors, maybe they were there from before :

documents_ _parse_pacecourier____ _ssh_root_159_203_35_195_ _226x64

Then I tried the hello cloud function from postman app to test for its output in pm2 logs and I got the following :

documents_ _parse_pacecourier____ _ssh_root_159_203_35_195_ _226x64

Next I try to run my sendMail sendgrid function and I find out the the api-key I had used in my sendgrid function was throwing an error
ReferenceError: XXXXXXXXXXXX is not defined

documents_ _parse_pacecourier____ _ssh_root_159_203_35_195_ _226x64

So I went back to my cloud code and used quotes around my api-key parameter and passed it as a string in my send grid initialize function. Then I retry and get

[Error: The provided authorization grant is invalid, expired, or revoked]

documents_ _parse_pacecourier____ _ssh_root_159_203_35_195_ _226x64_and_postman

So I went back to my sendgrid account and made sure that the api-key I was using was the correct one and it seemed to be just fine. I tested again and got the same error again so I decided to generate a new api-key just in case.

So I realize that I was not using the api-key but instead API KEY ID :

sendgrid_

When we create a new api-key on sendgrid they give us the actual api key once and they ask us to store it in some secure place :

We can only display the key above one time. Please store it somewhere safe because as soon as you navigate away from this page, we will not be able to retrieve or restore this generated token.

sendgrid_ _and_abubakar

So after I used an actual api-key I was able to send emails 😃

But one small issue still remains and I am not sure if its because of postman that I am using to run cloud code or something in the parse server or nginx that is still returning me with a 502 Bad Gateway as a response

postman

But when I look at the logs for my parse server I do see a

parse-wrapper-0 { message: 'success' }

documents_ parse_pacecourier___root ssh_root_159_203_35_195 _179x47

but it never gets back to me in my postman and instead i am getting a 502 error not sure why

Thanks for helping me debug

@drew-gross
Copy link
Contributor

This is expected. Also, now that you've posted your API keys, you should rotate them, or anyone can look at this page and send emails as your account.

@tanzeelrana
Copy link

Oh, my bad. Totally missed it. thanks :)

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

No branches or pull requests

5 participants