I try to send the mail using Meteor with Email package but mail not received
In client side i used this code
Meteor.call('sendEmail', 'xxx#sss.com', 'aaa#aat.com','Hello from Meteor!', 'This is a test of Email.send.');
In server side
Meteor.methods ({
sendEmail(to, from, subject, text) {
this.unblock();
Email.send({ to, from, subject, text });
}
});
In smptp.js
Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://XXXXXXX:6-2KklMXNG4prgdgdfgdgdfgo46ryaMCg#smtp.mandrillapp.com:587';
});
You can't set environment variables like that. You need to put it in your settings file, ie
{
"env": {
"MAIL_URL": "smtp://XXXXXXX:6-2KklMXNG4prgdgdfgdgdfgo46ryaMCg#smtp.mandrillapp.com:587"
}
}
and then when you run meteor
meteor --settings settings.json
Related
I'm using accounts.ui for forget password
Accounts.forgotPassword({email: "test#test.com"}, function (e, r) {
if (e) {
console.log(e.reason);
} else {
// success
}
});
When I send the email for forget password I simply get below email
Can someone tell me how to simply change the url and send the token with the same token
I tried using below code but that didn't work
main.js(client)
Meteor.startup(() => {
Accounts.resetPassword.text = function(user, url) {
url = url.replace('#/', '/');
console.log("url ==== ", url)
return `Click this link to reset your password: ${url}`;
}
});
On the server side:
Accounts.emailTemplates.resetPassword.subject = function () {
return "Forgot your password?";
};
Accounts.emailTemplates.resetPassword.text = function (user, url) {
return "Click this link to reset your password:\n\n" + url;
};
Read: https://docs.meteor.com/api/passwords.html#Accounts-emailTemplates
To change the resetPassword url to a custom one you have to run below code on your server (inside of /server/main.js file).
Accounts.urls.resetPassword = function (token) {
return FlowRouter.url("/reset-password/:token/", { token });
};
In this case, I am using a FlowRouter to generate that URL but you could technically just return a template literal if you like.
If the above code is in the server main.js file and you run Accounts.forgotPassword() function on the frontend from a localhost, it would generate this link:
http://localhost:3000/reset-password/C9cGfgaLEgGXbCVYJcCLnDYiRi3XJpmt2irLOOaKe56
I have created a server side route (using iron-router). Code is as follows :
Router.route( "/apiCall/:username", function(){
var id = this.params.username;
},{ where: "server" } )
.post( function(req, res) {
// If a POST request is made, create the user's profile.
//check for legit request
console.log('post detected')
var userId = Meteor.users.findOne({username : id})._id;
})
.delete( function() {
// If a DELETE request is made, delete the user's profile.
});
This app is running on port 3000 on my local. Now I have created another dummy app running on port 5000. Frrom the dummy app, I am firing a http.post request and then listening it on the app on 3000 port. I fire the http.post request via dummy app using the below code :
apiTest : function(){
console.log('apiTest called')
HTTP.post("http://192.168.1.5:3000/apiCall/testUser", {
data: [
{
"name" : "test"
}
]
}, function (err, res) {
if(!err)
console.log("succesfully posted"); // 4
else
console.log('err',err)
});
return true;
}
But I get the following error on the callback :
err { [Error: socket hang up] code: 'ECONNRESET' }
Not able to figure out whats the problem here.
The server side route is successfully called, but the .post() method is not being entered.
Using meteor version 1.6
192.168.1.5 is my ip addr
Okay so if I use Router.map function, the issue is resolved.
Router.map(function () {
this.route("apiRoute", {path: "/apiCall/:username",
where: "server",
action: function(){
// console.log('------------------------------');
// console.log('apiRoute');
// console.log((this.params));
// console.log(this.request.body);
var id = this.params.username;
this.response.writeHead(200, {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
});
if (this.request.method == 'POST') {
// console.log('POST');
var user = Meteor.users.findOne({username : id});
// console.log(user)
if(!user){
return 'no user found'
}
else{
var userId = user._id;
}
}
});
});
It looks like the content type is not set the application/json. So you should do that...
Setting the "Content-Type" header in HTTP.call on client side in Meteor
I'm trying to remove data in a collection, however, I'm getting remove failed: Access denied. I'm not sure what I'm doing wrong.
DB - Files.find
"_id": "",
"url": "",
"userId": "",
"added": ""
Path: file.js
Template.file.events = {
"click .delete-photo" : function () {
Files.remove(this._id);
}
};
If you are uninstall autopublish package use method as above answer:
Meteor.methods({
removePhoto: function (photoId) {
check(photoId, Meteor.Collection.ObjectID);
Files.remove(photoId);
});
And on your client:
Meteor.call("removePhoto", this._id, function(error, affectedDocs) {
if (error) {
console.log(error.message);
} else {
// Do whatever
console.log("success");
}
});
and if you uninstall insecure package please publishand subscribe the collection.
Meteor.publish('collectionname',function(){
return collectionname.find();
}
and subscribe:
Meteor.subscribe('collectionname);
You should consider making this into a Meteor method.
Server side code:
Meteor.methods({
removePhoto: function (photoId) {
check(photoId, Meteor.Collection.ObjectID);
Files.remove(photoId);
});
You should consider to remove the insecure and autopublish packages by typing these commands in your console:
meteor remove autopublish
meteor remove insecure
Below there is an example of how to publish the Files collection (here you also could add security features, such as only find and publish files belonging to user with correct id):
Meteor.publish('files',function(){
return Files.find();
}
And on your client:
Meteor.call("removePhoto", this._id, function(error, affectedDocs) {
if (error) {
console.log(error.message);
} else {
// Do whatever
console.log("success");
}
});
Here is the code for subscribing to the Files collection:
Meteor.subscribe('collectionname');
Read about methods, publish and subscribe over at Meteor docs. Links: http://guide.meteor.com/methods.html, https://www.meteor.com/tutorials/blaze/security-with-methods, https://www.meteor.com/tutorials/blaze/publish-and-subscribe
I want to be able to nose whatsapi in meteor. I am using
latest stable meteor
node-whatsapi
arunoda´s meteorhacks:npm
and can get the past the basics:
On meteor server startup, I have:
whatsapi = Meteor.npmRequire('whatsapi');
wa = whatsapi.createAdapter({
msisdn: '....',
username: '....',
password: '....',
ccode: '....'
});
wa.connect(function connected(err) {
if (err) {console.log(err); return;}
console.log('Connected');
wa.login(logged);
});
function logged(err) {
if (err) {console.log(err); return;}
console.log('Logged in');
wa.sendIsOnline();
};
... which let me send and receive messages with a method call to
wa.sendMessage(recipient, content, function(err, id) {
if (err) {console.log(err.message); return;}
console.log('Server received message %s', id);
});
The code bellow also works, logging received messages on the console. This sits inside server Meteor.startup:
wa.on('receivedMessage', function(message) {
console.log("From: " + message.from);
console.log(message.body);
});
My problem is that when I try to add store message.from or message.body into a collection, meteor gives me "Meteor code must always run within a Fiber" error")
wa.on('receivedMessage', function(message) {
console.log("From: " + message.from);
console.log(message.body);
Recipients.insert({msgfrom: message.from});
});
Help!
Use Meteor.bindEnvironment to wrap any callback given out by your npm module. It will wrap the callback into a 'Fiber' so you can run Meteor code in it.
For example:
wa.on('receivedMessage', Meteor.bindEnvironment(function(message) {
console.log("From: " + message.from);
console.log(message.body);
Recipients.insert({msgfrom: message.from});
}));
What it does essentially is place the code in the callback into a Fiber.
I am sending an email upon form input from a client. This is how I handle the input on the client side:
"submit .class-name": function(event) {
var text = event.target.text.value;
Meteor.call('sendEmail', text);
}
This is how I set up email and handle the function call on the server side:
Meteor.startup(function(){
process.env.MAIL_URL="smtp://email%40gmail.com:password#smtp.gmail.com:465/";
});
Meteor.methods({
sendEmail: function(text) {
Email.send({
from: "meteor.email.2014#gmail.com",
to: "email#gmail.com",
subject: "Meteor Can Send Emails via Gmail",
text: "asdf"//placeholder for now
});
}
});
EDIT: The issue was with the html form name.
Have you confirmed that your method is being called? Try adding a console.log('test') call to your method and see if it gets printed out in your meteor bash window when you call the method.