I'm using the SendGrid WebAPI for Node.js.
I followed these instructions:
I have the following code in a method I trigger from the client.
// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'test#example.com',
from: 'test#example.com',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);
When I trigger the method to send, I get an odd error (below) - Not sure why this is happening. Hoping for some ideas.
Thank you!!
ERROR:
(node:21240) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
W20190301-07:12:22.267(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:594:27)
W20190301-07:12:22.267(-8)? (STDERR) at Array.forEach (<anonymous>)
W20190301-07:12:22.268(-8)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20190301-07:12:22.268(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20190301-07:12:22.268(-8)? (STDERR) at Array.forEach (<anonymous>)
W20190301-07:12:22.268(-8)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20190301-07:12:22.268(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20190301-07:12:22.268(-8)? (STDERR) at Array.forEach (<anonymous>)
W20190301-07:12:22.268(-8)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20190301-07:12:22.268(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20190301-07:12:22.268(-8)? (STDERR) at Array.forEach (<anonymous>)
W20190301-07:12:22.268(-8)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20190301-07:12:22.269(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20190301-07:12:22.269(-8)? (STDERR) at Array.forEach (<anonymous>)
W20190301-07:12:22.269(-8)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20190301-07:12:22.269(-8)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20190301-07:12:22.269(-8)? (STDERR) (node:21240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)
First of all, by putting your API_KEY on the client side, you're showing it, and it should be kept secret.
Create a new file server/smtp.js. By putting it in a server/ directory, Meteor will put it only on the server side, this code will not be visible from the client side:
Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://username:password#smtp.sendgrid.net:587';
});
Add the email package to meteor. On the command line:
meteor add email
Create a file server/methods.js to add some server side methods:
Meteor.methods({
sendmail(to) {
// for security reasons, you should validate the 'to' argument
// but let's forget that for now.
Email.send({
from: "me#paulpedrazzi.com",
to: to
subject: "Awesome",
text: "It worked"
});
}
});
Whenever you want to send an email, on the client side call this method and pass it the necessary arguments:
Meteor.call('sendmail', ‘elon.musk#tesla.com’, (err, res) => {
if (err) {
alert(err);
} else {
// success!
}
});
Hope it helps.
Related
I'm just working through the update to 1.3 and not sure how to handle this error. I'm thinking it might have to do with file load order changing in 1.3. Any ideas? Thanks!
W20160407-09:54:43.528(1)? (STDERR) /Users/technical/.meteor/packages/meteor-tool/.1.3.1.10rlef4++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:267
W20160407-09:54:43.528(1)? (STDERR) throw(ex);
W20160407-09:54:43.528(1)? (STDERR) ^
W20160407-09:54:43.553(1)? (STDERR) TypeError: Cannot read property 'path' of undefined
W20160407-09:54:43.553(1)? (STDERR) at Routing (packages/lookback:emails/lib/routing.js:17:9)
W20160407-09:54:43.554(1)? (STDERR) at packages/lookback:emails/lib/mailer.js:279:11
W20160407-09:54:43.554(1)? (STDERR) at Array.forEach (native)
W20160407-09:54:43.554(1)? (STDERR) at packages/lookback:emails/lib/mailer.js:278:28
W20160407-09:54:43.554(1)? (STDERR) at Function._.each._.forEach (packages/underscore.js:147:22)
W20160407-09:54:43.554(1)? (STDERR) at Object.init (packages/lookback:emails/lib/mailer.js:274:9)
W20160407-09:54:43.554(1)? (STDERR) at Object.Mailer.init (packages/lookback:emails/lib/mailer.js:303:7)
W20160407-09:54:43.554(1)? (STDERR) at app/server/lib/config/config.js:72:8
W20160407-09:54:43.554(1)? (STDERR) at /Users/technical/code/mssc1.3/.meteor/local/build/programs/server/boot.js:290:5
server/lib/config/config.js
Meteor.startup(function() {
this.Templates = {}
Templates.remindEventEmail = {
path: 'remindEventEmail.html'
};
Mailer.init({
templates: Templates
});
});
private/remindEventEmail.html
<p>Email code<p>
it's not a 1.3 thing, it's a lookback > 0.7.0 thing
if you don't need email previews, simply setting
Mailer.config({
addRoutes: false
});
may fix your problem.
otherwise follow along for how I use it with Flow Router
according to:
you now need to supply a route field on your template object
https://github.com/lookback/meteor-emails#version-history
route: {
path: '/sample/:name',
// params is an object, with potentially named parameters, and a `query` property
// for a potential query string.
data: function(params) {
// `this` is the HTTP response object.
return {
name: params.name // instead of this.params.name
};
}
}
so your
Templates.remindEventEmail = {
path: 'remindEventEmail.html'
};
should become
Templates.remindEventEmail = {
path: 'remindEventEmail.html'
route: {
path: '/event/:_id/remind',
data: function(params) {
return {
event: Events.findOne(params._id);
}
}
}
};
the actual route would then be /emails/event/:_id/remind
please notice the data pattern, you might use another style of query or nesting of the main data context
I am trying to get Meteors accounts-password working with neo4j. The "logon" was already cleared in one Topic here, my problem is: How can I get Accounts.createUser to work with Neo4j?
Thanks!
At the moment I am trying with:
Meteor.startup(function () {
Accounts.users = Meteor.neo4j.collection('User');
Accounts.createUser({username: 'admin', password: 'admin'});
});
But this Error is thrown:
W20151005-19:43:41.165(2)? (STDERR) { error:
W20151005-19:43:41.166(2)? (STDERR) { [Error: Property values can only be of primitive types or arrays thereof]
W20151005-19:43:41.166(2)? (STDERR) message: 'Property values can only be of primitive types or arrays thereof' },
W20151005-19:43:41.166(2)? (STDERR) uid: 'f0deded1be5deeb03ae2b29de735d81c8ee45fa518600dd16bc5cdf7de581bec',
W20151005-19:43:41.166(2)? (STDERR) optuid: '6ebc087e0a93a04473772df8d4c2ded5ee59987ee7a870dbc0802930c565d39b',
W20151005-19:43:41.167(2)? (STDERR) query: 'MATCH (n {_id: {_id}}) WITH count(n) AS count_n WHERE count_n <= 0 CREATE (n {properties})',
W20151005-19:43:41.167(2)? (STDERR) opts:
W20151005-19:43:41.167(2)? (STDERR) { properties:
W20151005-19:43:41.167(2)? (STDERR) { createdAt: Mon Oct 05 2015 19:43:41 GMT+0200 (CEST),
W20151005-19:43:41.167(2)? (STDERR) services: [Object],
W20151005-19:43:41.167(2)? (STDERR) username: 'admin',
W20151005-19:43:41.168(2)? (STDERR) _id: '7Dy7t5iJRbj84tFGa' },
W20151005-19:43:41.168(2)? (STDERR) _id: '7Dy7t5iJRbj84tFGa' },
W20151005-19:43:41.168(2)? (STDERR) date: Mon Oct 05 2015 19:43:41 GMT+0200 (CEST) }
My meteor application does not download previously stored documents.
Initially I thought I was having problems with ongoworks:security support for CollectionFS.
RsrchDocs.files.permit(['download']).apply() causes Invalid key errors. Have read the ongoworks:security docs and CollectionFS docs multiple times without finding my error. The Github repository for "ongoworks:security issues 4, 17, 20 appear to address this problem. It is not clear that the issues raised were ever fully resolved. I have tried the suggestions without success. Since RsrchDocs.allow({...}) (option B) allows the server to (re)start without error I may (probably?) have another error preventing the download.
With option A or B in place, hovering over the download link in the browser displays the correct URL, but clicking the link does not initiate the download. Manually copying the URL into the address field and submitting that does successfully download the document.
What should I do/change in my meteor app to successfully download a previously stored document?
server/security.js
RsrchDocs.files.permit(['insert', 'update', 'remove']).apply();
// Option A:
// Uncommented causes "(STDERR) Error: EBADF, read" on (re)start
// Document download is NOT permitted.
//Security.permit(['download']).collections([RsrchDocs]).apply();
// Option B:
// Uncommented (re)starts without any error message
// Document download is NOT permitted
//RsrchDocs.allow({
// download: function(userId, doc){
// return true;
// }
//});
// Option C:
// Uncommented (re)starting meteor causes multiline error message
// Server start fails
//RsrchDocs.files.permit(['download']).apply();
// The error messages:
[[[[[ C:\Users\loco\My Projects\Meteor\research ]]]]]
=> Started proxy.
=> Started MongoDB.
I20150817-10:38:58.532(-5)? Meteor._wrapAsync has been renamed to Meteor.wrapAsync
=> Started your app.
=> App running at: http://localhost:3000/
Type Control-C twice to stop.
(STDERR) Error: EBADF, read
Meteor._wrapAsync has been renamed to Meteor.wrapAsync
(STDERR)
(STDERR) C:\Users\loco\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
(STDERR) throw(ex);
(STDERR) ^
(STDERR) Error: allow: Invalid key: download
(STDERR) at packages/mongo/collection.js:723:1
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR) at [object Object].addValidator (packages/mongo/collection.js:721:1)
(STDERR) at [object Object].Mongo.Collection.allow (packages/mongo/collection.js:769:1)
(STDERR) at packages/ongoworks:security/security-util.js:39:1
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR) at addFuncForAll (packages/ongoworks:security/security-util.js:38:1)
(STDERR) at packages/ongoworks:security/security-util.js:56:1
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR) at ensureCreated (packages/ongoworks:security/security-util.js:52:1)
(STDERR) at ensureDefaultAllow (packages/ongoworks:security/security-util.js:70:1)
(STDERR) at SecurityRuleConstructor.Security.Rule.apply (packages/ongoworks:security/security-api.js:76:1)
(STDERR) at app\server\security.js:18:38
(STDERR) at app\server\security.js:22:3
(STDERR) at C:\Users\loco\My Projects\Meteor\research\.meteor\local\build\programs\server\boot.js:222:10
(STDERR) at Array.forEach (native)
(STDERR) at Function._.each._.forEach (C:\Users\loco\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
(STDERR) at C:\Users\loco\My Projects\Meteor\research\.meteor\local\build\programs\server\boot.js:117:5
=> Exited with code: 8
Meteor._wrapAsync has been renamed to Meteor.wrapAsync
lib/collections/rsrchDocs.js
RsrchDocs = new FS.Collection("rsrchDocs", {
stores: [new FS.Store.FileSystem("rsrchDocs")]
});
if(Meteor.isClient){
Meteor.subscribe('RsrchDocs')
}
// server/publish.js
Meteor.publish('RsrchDocs', function(){
return RsrchDocs.find({});
});
client/documents/templates.html
<template name='subjDocs'>
<div id='upload' class='upload'>
{{> upload}}
</div>
<div class="col-xs-12" id="docsTable">
{{> reactiveTable collection=subjDocs settings=docSettings }}
</div>
</template>
client/documents/helpers.js
Template.subjDocs.helpers({
subjDocs: function() {
return RsrchDocs.find({ 'metadata.subjId': this._id });
},
docSettings: function(){
return {
fields: [
{ key: 'metadata.subjId', label: 'Subject', hidden: false },
// ...
{ key: 'original.name', label: 'Name',
fn: function(value, object) {
var docName = value;
var dnloadURL = object.url({download: true});
var linkStr = "<a href= '"+dnloadURL+"' >"+docName+"</a>";
return Spacebars.SafeString(linkStr);
},
},
],
};
}
});
client/documents/events.js
Template.subjDocs.events({
'click .reactive-table tr': function (event) {
event.preventDefault();
var subjDoc = this;
switch (event.target.className) {
case 'delete':
if( confirm && subjDoc ) {
subjDoc.remove()
};
return false;
break;
//case ...
};
},
});
Environment:
Windows 7
C:\Users\ ... \research>meteor list
accounts-password 1.1.1
alanning:roles 1.2.13
aldeed:autoform 5.4.1
aldeed:collection2 2.3.3
aldeed:simple-schema 1.3.3
aslagle:reactive-table 0.8.11
cfs:ejson-file 0.1.4
cfs:filesystem 0.1.2
cfs:gridfs 0.0.33
cfs:standard-packages 0.5.9
cfs:ui 0.1.3
email 1.0.6
fortawesome:fontawesome 4.4.0
ian:accounts-ui-bootstrap-3 1.2.77
iron:router 1.0.9
meteor-platform 1.2.2
ongoworks:security 1.2.0
raix:ui-dropped-event 0.0.7
reactive-var 1.0.5
sanjo:jasmine 0.17.0
twbs:bootstrap 3.3.5
velocity:html-reporter 0.8.2
I just finished developing a Meteor package. Now I want to test it by adding it to a new Meteor app:
my_cool_package_name/package.js
Package.on_use(function(api){
api.use("accounts-password#1.1.1");
});
Add my_cool_package_name to a new project
meteor add my_cool_package_name
Changes to your project's package version selections:
accounts-base added, version 1.2.0
accounts-password added, version 1.1.1
List installed packages
meteor list
meteor-platform 1.2.2 Include a standard set of Meteor packages in your app
my_cool_package_name 1.0.0+ This is my_cool_package_name
Start meteor
meteor
ReferenceError: Accounts is not defined
W20150817-15:30:49.707(-4)? (STDERR) at manage_users_log.insert.username (app/server/fixtures.js:7:17)
W20150817-15:30:49.707(-4)? (STDERR) at Array.forEach (native)
W20150817-15:30:49.707(-4)? (STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
W20150817-15:30:49.708(-4)? (STDERR) at app/server/fixtures.js:6:4
W20150817-15:30:49.708(-4)? (STDERR) at app/server/fixtures.js:36:3
W20150817-15:30:49.708(-4)? (STDERR) at /Users/me/Documents/meteor/my_app/.meteor/local/build/programs/server/boot.js:222:10
W20150817-15:30:49.708(-4)? (STDERR) at Array.forEach (native)
W20150817-15:30:49.708(-4)? (STDERR) at Function._.each._.forEach (/Users/me/.meteor/packages/meteor-tool/.1.1.4.1kp2n64++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150817-15:30:49.708(-4)? (STDERR) at /Users/me/Documents/meteor/my_app/.meteor/local/build/programs/server/boot.js:117:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
server/fixtures.js
if (Meteor.users.find().count() === 0) {
var users = [
{username:'admin',email:'admin#example.com',password:'adminadmin',roles:['admin'],status:'enabled',profile:{first_name:'admin',last_name:'admin'}},
{username:'user',email:'user#example.com',password:'useruser',roles:['user'],status:'enabled',profile:{first_name:'user',last_name:'user'}}
];
_.each(users, function(user){
var user_id = Accounts.createUser({
username: user.username,
email: user.email,
password: user.password,
profile: {
first_name: user.profile.first_name,
last_name: user.profile.last_name,
}
});
Meteor.users.update(
{_id: user_id},
{$set:
{
roles: user.roles,
status: user.status
}
}
);
});
}
if (manage_users_log.find().count() === 0) {
manage_users_log.insert({
username: "admin",
category: "server_startup",
description: "Meteor server started."
});
}
If it helps, the app structure is laid out like so:
client
my_app.html
packages
my_cool_package_name
server
fixtures.js
Use api.imply to give your app access to the exported symbols of your package dependencies.
Package.onUse(function(api){
api.use("accounts-password#1.1.1");
//
api.imply("accounts-password#1.1.1");
});
When you add a package depending on other packages, their exported symbols are not available to the main app, you need to imply them to make this happen.
In my meteor app I'm using a bootstrap table, which requires query.
I ran "meteor add query", and it is listed in the "packages" file:
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
standard-app-packages
autopublish
insecure
reactive-dict
bootstrap
js-base-model
jquery
iron-router
The file (table.js) is located under /lib:
(function(){
'use strict';
var $ = jQuery;
$.fn.extend({
filterTable: function(){
return this.each(function(){
$(this).on('keyup', function(e){
$('.filterTable_no_results').remove();
var $this = $(this), search = $this.val().toLowerCase(), target = $this.attr('data-filters'), $target = $(target), $rows = $target.find('tbody tr');
if(search == '') {
$rows.show();
} else {
$rows.each(function(){
var $this = $(this);
$this.text().toLowerCase().indexOf(search) === -1 ? $this.hide() : $this.show();
})
if($target.find('tbody tr:visible').size() === 0) {
var col_count = $target.find('tr').first().find('td').size();
var no_results = $('<tr class="filterTable_no_results"><td colspan="'+col_count+'">No results found</td></tr>')
$target.find('tbody').append(no_results);
}
}
});
});
}
});
$('[data-action="filter"]').filterTable();
})(jQuery);
$(function(){
// attach table filter plugin to inputs
$('[data-action="filter"]').filterTable();
$('.container').on('click', '.panel-heading span.filter', function(e){
var $this = $(this),
$panel = $this.parents('.panel');
$panel.find('.panel-body').slideToggle();
if($this.css('display') != 'none') {
$panel.find('.panel-body input').focus();
}
});
$('[data-toggle="tooltip"]').tooltip();
})
When I run the meteor command from the app root directory I get the following error:
Eugenes-MacBook-Pro-3:wizard eugene$ meteor
[[[[[ ~/Documents/DevTraining/meteor/wizard ]]]]]
=> Started proxy.
=> Started MongoDB.
W20140407-22:43:54.117(-5)? (STDERR)
W20140407-22:43:54.153(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:54.154(-5)? (STDERR) }).run();
W20140407-22:43:54.154(-5)? (STDERR) ^
W20140407-22:43:54.154(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:54.154(-5)? (STDERR) at app/lib/table.js:28:4
W20140407-22:43:54.155(-5)? (STDERR) at app/lib/table.js:46:3
W20140407-22:43:54.155(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:54.155(-5)? (STDERR) at Array.forEach (native)
W20140407-22:43:54.155(-5)? (STDERR) at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:54.155(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
W20140407-22:43:54.803(-5)? (STDERR)
W20140407-22:43:54.803(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:54.803(-5)? (STDERR) }).run();
W20140407-22:43:54.803(-5)? (STDERR) ^
W20140407-22:43:54.806(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:54.806(-5)? (STDERR) at app/lib/table.js:28:4
W20140407-22:43:54.806(-5)? (STDERR) at app/lib/table.js:46:3
W20140407-22:43:54.806(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:54.806(-5)? (STDERR) at Array.forEach (native)
W20140407-22:43:54.806(-5)? (STDERR) at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:54.806(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
W20140407-22:43:55.496(-5)? (STDERR)
W20140407-22:43:55.496(-5)? (STDERR) /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:186
W20140407-22:43:55.497(-5)? (STDERR) }).run();
W20140407-22:43:55.497(-5)? (STDERR) ^
W20140407-22:43:55.499(-5)? (STDERR) ReferenceError: jQuery is not defined
W20140407-22:43:55.499(-5)? (STDERR) at app/lib/table.js:28:4
W20140407-22:43:55.499(-5)? (STDERR) at app/lib/table.js:46:3
W20140407-22:43:55.499(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:155:10
W20140407-22:43:55.499(-5)? (STDERR) at Array.forEach (native)
W20140407-22:43:55.499(-5)? (STDERR) at Function._.each._.forEach (/Users/eugene/.meteor/tools/c2a0453c51/lib/node_modules/underscore/underscore.js:79:11)
W20140407-22:43:55.500(-5)? (STDERR) at /Users/eugene/Documents/DevTraining/meteor/wizard/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
What could I do to resolve this?
jQuery is a client-side only library, you cannot use it on the server side – This error is thrown because jQuery is not defined there. To fix it, limit your code to client-side, either by placing it in /client folder (or /client/lib if you want it to have priority when loading), or by wrapping the code in
if (Meteor.isClient) {
...
}