lookback / meteor-emails

Improved Meteor emails with templating, previews and automated CSS/SCSS inlining.

Home Page:https://atmospherejs.com/lookback/emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mailer.send returns undefined

sean-stanley opened this issue · comments

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.

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?

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

@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.

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

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