未加星标

Send emails with Ember.js + Amazon SES + Firebase

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

There is a need to build client side only (front end) applications. Tools like Ember CLI , Create react app , Angular 2 CLI make it very easy to bootstrap a javascript app in just a few minutes and start building features.

The challenge arises when you need to add a piece of server side logic, like sending emails, uploading files, authentication, or storing some data to the database. In most cases, it doesn’t make sense to add a full blown server, which requires to be maintained and setup. All you want is one or two server side features, right? :wink:

Firebase can solve that problem (partially). It adds missing server side components to your front-end application without managing a server. Think of it as a NoSQL database with built-in API and some extra features like analytics, hosting and authentication.

All examples here are for Ember.js, since that’s the project I was working on when I had the need to add a contact form. But it can be applied to any front end framework where the server is not available or cost effective.

The goal

When the user submits a form on a website, it saves the submitted data in the database for future reference and sends an email notification to the website admin containing all the submitted values. This is a simple feature, which comes for free with any CMS or server side framework (WordPress, Ruby on Rails, etc). But this simple feature requires a server. And we don’t want to add server…


Send emails with Ember.js + Amazon SES + Firebase
The solution

We are combining Firebase and AWS simple email service (SES). For low traffic websites ― free tier on both services will last you a long time. When the user submits a form ― we send an email and save it to the database in parallel.

Here is an implementation for firebase. Add EmberFire to your project. After adding API keys to enviroment.js , you can start using firebase in your code. Let’s say we have contact.js controller, which handles the form’s “submit” action.

Example of partial ember controller that handles actions

That’s all you need to do to save ANY data to Firebase using EmberFire adapter. Pretty easy.

Now, in an ideal world, Firebase would trigger some kind of event and send out an email notifying our admin that the record has been created. But it’s not yet supported. We can use Amazon SES instead for this.

Sign up for an Amazon account Verify the email address (check your email and click the link). Pay attention to the region, verification, prices and limits that are region specific.
Send emails with Ember.js + Amazon SES + Firebase

3. By default, the basic account is in sandbox mode. Which means you can only send test emails to verified emails. Request a limit increase in order to be able to send emails en masse. Here is a more detailed documentation . I got mine approved to 50K emails per day within 24 hours (thanks Amazon)

4. Add AWS npm package npm install aws-sdk -s , and then add ember-browserify so we can access the npm package in the browser.

Here is the full contact.js controller:

By combining PaaS like AWS, Firebase and others we can pick and choose what server side features we want to bring to our front end applications without maintaining the servers.

Need help with React.js / Redux / Ember.js / Node.js? Check out http://ecmastack.com

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

分页:12
转载请注明
本文标题:Send emails with Ember.js + Amazon SES + Firebase
本站链接:http://www.codesec.net/view/531598.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(47)