neocorp
neocorp

Reputation: 569

Parse main.js Mandrill HTML mail sending issue

I have a cloud function on Parse in main.js where I send mail as HTML encoded with Mandrill API. I call this function through my iOS app posting some parameters and its perfectly ok, sends the email. However I want to localize the HTML body depending on the language of user. Since I checked the iOS in-line HTML options which are very tricky, I'm trying to do it in my sendMail function on main.js:

Parse.Cloud.define("sendMail", function(request, response) {
    var Mandrill = require('mandrill');
    Mandrill.initialize('APP_ID');
    var locale = request.params.locale;
    var userName = request.params.user;
    var password = request.params.pass;
    var HTMLBodyEn = '<p>text</p>';
    var HTMLBody = HTMLBodyEn;
    if (locale == 'tr') {
        HTMLBody = '<p>yazı</p>';
    }

    Mandrill.sendEmail({
        message: {
            html: HTMLBody,
            subject: request.params.subject,
            from_email: request.params.fromEmail,
            from_name: request.params.fromName,
            to: [
                {
                    email: request.params.toEmail,
                    name: request.params.toName
                }
            ]
        },
        async: true
    },{
        success: function(httpResponse) {
            console.log(httpResponse);
            response.success("Email sent!");
        },
        error: function(httpResponse) {
            console.error(httpResponse);
            response.error("Uh oh, something went wrong");
        }
    });
});

Well it's simple as that. If condition you see there causes all the problem... As you can see there I'm receiving a locale key to change the body but it doesn't and Parse returns 141 error code which means after some digging is a time-out exception.

I can't seem to understand that a simple if statement as that causes a timeout.

Can anyone help me on this? Encountered anything similar?

Upvotes: 1

Views: 587

Answers (1)

ryanjduffy
ryanjduffy

Reputation: 5215

You might be experiencing side effects from a text encoding issue. The Mandrill SDK on parse doesn't appear to handle the charset you're using. Take a look at this post from their forums that offers a workaround for that problem.

https://www.parse.com/questions/sometimes-getting-mandrill-you-must-specify-a-key-value-error-when-sending-email

Upvotes: 0

Related Questions