Help with inserting a collection then sending an email using Aldeed Autoform

I"m using autoform and trying to insert a collection then using onsubmit hook call a server method to send an email based on the collections i’m inserting. Is this possible to do. I’m looking at the autoform documentation and I see where you can use type method on the template. The only problem is I want to store the contact information in a collection than send the emails out. The examples I’ve seen seem to send the emails only then reset the form. Any help would be appreciated.

Use AutoForm.hook and the onSuccess option to do a when your autoform has completed. Or You can use matt33’s collection hook to do a Collection.after.insert( function(doc,userId){}); Both are pretty great ways to solve the \issue.

thanks I used the meteor call option and was able to accomplish what I needed.

Hi ajlaz, can you please share with us how u solve the problem. Am having the same problem.

I used onSuccess in my collection hook, then within my meteor call I queried the collection and looped through each email sending it out from within the method call. Im using pretty emails package and I have a mailgun account also to send emails out.

var collectionHooks = {

onSuccess: function(formType, result) {‘sendEmailInvite’);


AutoForm.addHooks(‘insertCollectionForm’, collectionHooks);

sendEmailInvite: function () {
console.log("inside sendEmailInvite ");
var emails = EmailsCollection.findOne({createdBy: this.userId});

_.each(emails.invite, function(emailData){
  console.log("sending email to: ";
  PrettyEmail.send( 'call-to-action', {
    subject: '',
    heading: '',
    message: '',
    buttonText: '',
    buttonUrl: ''


1 Like

Thanks, you are a lifesaver.
But having difficult reading from the database using emailData plus, am not using the prettyEmail stuff.

This should be done on the server side? If you are then emailData should reference your list of emails stored in the db. In my case I have a invites embedded document that contains emails.

Check out the email package in the official Meteor docs: