Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Mailer.send returns undefined #89

Open
sean-stanley opened this issue Mar 8, 2017 · 5 comments
Open

Mailer.send returns undefined #89

sean-stanley opened this issue Mar 8, 2017 · 5 comments

Comments

@sean-stanley
Copy link
Contributor

Hi,

I have a simple method that calls Mailer.send then if the result is true, updates the database.

Then in my unit test, result is undefined. I think it might be undefined outside the testing environment as well.

The documentation says that Mailer.send returns either true or false though. Has the API been updated? Does it behave differently in different environments?

This is occurring on Meteor 1.4

Love the package by the way, thank you for your work on it and for sharing it with the community. Being able to structure my email templates in an easy and orderly way is so handy.

@johanbrook
Copy link
Contributor

Hi there, sorry for the slow turn around on this.

The relevant code is here: https://github.com/lookback/meteor-emails/blob/master/lib/mailer.js#L266-L275. So unless settings.disabled is true, it should use Emails.send and return true.

Is the email sent at all?

@kjrhody
Copy link

kjrhody commented Mar 1, 2018

II think I'm having a similar issue. I am trying to call Mailer.send from inside a click function (can I do that?). My code is as follows:

Template.secondReviewStatus.events({
    'click #reviewReady': function(event,template){
        let graphicId = this._id;
        let reviewReady = $(event.currentTarget).data('reviewready');
        let graphic = this;

        Graphics.update({_id: graphicId}, {$set: {reviewStatus: reviewReady}}, function(error, result){
            if(error){
                sAlert.error('Error updating graphic: ' + error);
                throw new Meteor.Error("Error updating graphic");
            }
        });

                function getGraphicsMetadataNotificationRecipients(project_identifier){
                    return Meteor.users.find({"roles.__global_roles__": {$all: ['email-graphics-metadata', project_identifier]}}).fetch().map((user) => {
                        return user.emails[0].address;
                });
                }

                let graphicsMetadataRecipients = getGraphicsMetadataNotificationRecipients(graphic.project_identifier);
                let chapter = Chapters.findOne(graphic.chapterId);
                let projectAcronym = Projects.findOne({identifier: graphic.project_identifier}).acronym;
               let chapterName = chapter.number;
              
                let subject = [projectAcronym + ":", + "Chp "+ chapterName + "," + " Fig " + graphic.figureNum, 'ready for metadata review'].join(' ');

                if(graphicsMetadataRecipients.length > 0) {
                    Mailer.send({
                        to: graphicsMetadataRecipients,
                        subject: subject,
                        template: 'graphicMetadataReviewReady',
                        data: {
                            chapter: chapter,
                            graphic: graphic
                        }
                    });
                }
    },

I get Uncaught ReferenceError: Mailer is not defined

@johanbrook
Copy link
Contributor

@kjrhody Hi! Hm, no I think it's because you're trying to use Mailer on the client – this is a server only package, so try using a Meteor method on the server which the client calls instead.

@kjrhody
Copy link

kjrhody commented Mar 1, 2018

Thanks! Excuse my ignorance, I'm very new to all of this. I'll give that a shot.

@johanbrook
Copy link
Contributor

@kjrhody No worries at all :) Read up on Methods in here.

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

No branches or pull requests

3 participants