Adding e-mail to simple-todos


#1

I would like to add a second form to simple-todos that will send an e-mail with the to-do list. I’ve added to the .css and html, so I see them on my page. Just having trouble with calling the .js action.

Here is what I added.

simple-todos.html

in the body
{{> sendEmail}}

a new template:

#


E-mail Address:



Send E-mail


simple-todos.js

Template.sendEmail.events({
“submit .sendEmail”: function (event) {
var text = event.target.email.value
Meteor.call(‘sendEmail’,
text,
‘bob@example.com’,
‘Hello from Meteor!’,
‘This is a test of Email.send.’);

 // Clear form
  event.target.email.value = "";

  // Prevent default form submit
  return false;
}

});

simple-todos.css

.send-email {
margin-top: 10px;
margin-bottom: -10px;
position: relative;
margin-left: 1em;
}

.email-label input {
border: none;
}

.email-label input:focus{
outline: 0;
}

.email {
font-weight: bold;
background: none;
font-size: 1em;
position: relative;
}


#2

Did you define a server side method called “sendEmail”?


#3

This is what I have.

#// A method that the client can call because only the server can send e-mails
Meteor.methods({
sendEmail: function (to, from, subject, text) {
check([to, from, subject, text], [String]);

// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();

Email.send({
  to: to,
  from: from,
  subject: subject,
  text: text
});

}