How do I send emails using Pony and Sinatra?


#1

I am trying to make an ajax request in Ember that sends a user and email after they submit their email address. I am using Pony to send emails and Sinatra in the back end. The ajax request data is blank because I’m not sure how to go about it or if this is the correct way to go. This is what I have:

POST email

post '/v1/email' do
Pony.mail :to => "dahjoyner12@gmail.com",
:from => "noreply@soi.com",
:subject => "Welcome",
:body => "hello",
:via => :smtp,
:via_options => {
    :address  => 'smtp.gmail.com',
    :port     =>  '9393'
    }
end

forgot-password-form.js

import Component from '@ember/component';

export default Component.extend({

buttonLabel: 'Save',

actions: {
buttonClicked(item) {
console.log('email form');
this.sendAction('verify', item);
}
}
});

forgot-password.js

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
model() {
return this.get('store').findAll('user');
},

ajax: service(),

actions: {
verify() {
  return this.get('ajax').post('/email', {
    data: {

    }
  });
}
}
});

#2

This looks OK so far. Presumably you need to put something about the current into into the POST body? You can pass arguments through actions, so for example if the user is available in the forgot-password-form component, it can this.sendAction('verify', this.get('user')), and then the verify action will receive the user as an argument and can put the right things into the ajax post.