Skip to content

Cloud Code Error Internal Server Error 1 using Mailgun #1258

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

Closed
greatis opened this issue Mar 29, 2016 · 8 comments
Closed

Cloud Code Error Internal Server Error 1 using Mailgun #1258

greatis opened this issue Mar 29, 2016 · 8 comments

Comments

@greatis
Copy link

greatis commented Mar 29, 2016

I use Parse Server on the Google Cloud.
Migration works well.
I am able to read information from my classes, upload files.

  1. My cloud hello function works well.
  2. I made a simple Cloud.HttpRequest function.
    It works.
  3. Mailgun module gives me always "Internal Server Error", code 1 .
    I use this module:
    https://github.com/ParsePlatform/JavaScriptModulesTutorial

Parse.Cloud.define("sendMail", function(request, response) {
var Mailgun = require('/my path/mailgun.js');
Mailgun.initialize('my-domaun,'api-key');
var stext=request.params.text.replace(/\n/g,'\n');

console.log('text: '+stext);

Mailgun.sendEmail({
to: "[email protected]",
from: request.params.fromEmail,
subject: request.params.subject,
text: stext
},{
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});

  1. I cannot find a way to how to debug cloud code.
    There is no saved cloud code log.
    I cannot find the step by step instructions how to store log to file.
    I think it is important to have a simple switch to activate the log.
    Thanks.
@gfosco
Copy link
Contributor

gfosco commented Mar 29, 2016

Check the logs from the server when this is executed. It should be printing something out if it's hitting an internal server error.

@greatis
Copy link
Author

greatis commented Mar 29, 2016

I see no errors on Mailgun server.
Seems like this is my parse server error:
{"code":1,"error":"Internal Server Error"}

@gfosco
Copy link
Contributor

gfosco commented Mar 29, 2016

I mean the logs from your parse-server instance. Run it locally and test. Often if the server responds with code 1, the server instance will have logged a stack trace to the console.

@greatis
Copy link
Author

greatis commented Mar 29, 2016

But I don't know where to see the logs from cloud code.

@flovilmart
Copy link
Contributor

did you import mailgun with require('parse-mailgun')? If that's the case, it's not available in cloud code...

@greatis
Copy link
Author

greatis commented Apr 1, 2016

I use myMailModule-1.0.0.js
I use the full path in require:
var Mailgun = require('/full path/myMailModule-1.0.0.js ');

@hramos
Copy link
Contributor

hramos commented Apr 1, 2016

It is not clear that this is an issue in Parse Server, as it concerns "third party" JavaScript code that is being pulled into Cloud Code. I recommend adding logs to your myMailModule-1.0.0.js file to see what Mailgun is responding with.

PS: I am aware that myMailModule.js is one of Parse's own JavaScript examples, but it was written with hosted Parse applications in mind.

@hramos hramos closed this as completed Apr 1, 2016
@jforaker
Copy link

jforaker commented Jun 3, 2016

Fwiw, you need to use a third party Mailgun module such as https://github.com/bojand/mailgun-js (NOT anything Parse specific - Mailgun.initialize(...) will not work anymore)

Then it is easy as this inside your cloud code function:

var mailgun = require('mailgun-js')({apiKey: process.env.MAILGUN_KEY, domain: 'mg.yourapp.com'});

            var mail = {
                from: '[email protected]',
                to: toEmail,
                subject: subject,
                body: '',
                html: htmlBody
            };

            mailgun.messages().send(mail, function (sendError, body) {
                if (error) {
                    inspect(sendError, 'mailgun sendError');
                } else {
                    inspect(body, 'Successfully send RECEIPT email to "' + toEmail + '"');
                }
            });

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