Skip to content

Commit bf20f99

Browse files
committed
Initial Commit
0 parents  commit bf20f99

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'sinatra'
4+
gem 'sinatra-contrib'

Gemfile.lock

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
backports (3.3.3)
5+
multi_json (1.8.0)
6+
rack (1.5.2)
7+
rack-protection (1.5.0)
8+
rack
9+
rack-test (0.6.2)
10+
rack (>= 1.0)
11+
sinatra (1.4.3)
12+
rack (~> 1.4)
13+
rack-protection (~> 1.4)
14+
tilt (~> 1.3, >= 1.3.4)
15+
sinatra-contrib (1.4.1)
16+
backports (>= 2.0)
17+
multi_json
18+
rack-protection
19+
rack-test
20+
sinatra (~> 1.4.0)
21+
tilt (~> 1.3)
22+
tilt (1.4.1)
23+
24+
PLATFORMS
25+
ruby
26+
27+
DEPENDENCIES
28+
sinatra
29+
sinatra-contrib

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<h3>Using Mandrill Email API</h3>
2+
3+
I was working on a hackathon project last weekend, and we need a quick way to send emails out from our Sinatra application. At first we tried to integrate the <a href="https://rubygems.org/gems/gmail" target="_blank">gmail gem</a>, but after realizing that is an easy way to get that account flagged at spam, we decided to turn to Mandrill by Mailchimp.
4+
5+
I'll show you how to
6+
<ul>
7+
<li>integrate the Mandrill API</li>
8+
<li>how to send mail with the Mandrill API</li>
9+
<li>and some quick advanced features in the mandrill API</li>
10+
<ul>
11+
<li>How to send with multiple users in To and other fields</li>
12+
<li>How to suppress users from the To field</li>
13+
<li>How to use the Mandrill Test Key to make the email call but not actually push out an email to count against your monthly API call limit.</li>
14+
<li>How to use "Merge Fields" in Mandrill to merge in custom URL's and data into the email about the user you are sending to.</li>
15+
</ul>
16+
</ul>
17+
18+
__________________________
19+
20+
<h4>Example APP: My Penpal</h4>
21+
22+
We are going to build a quick application to send emails out to users who subscribe to your mailing list.
23+
24+
I created a bare bones Rails App for this tutorial on using Mandrill.
25+
26+
__But first, lets get a Mandrill account.__
27+
28+
<h4>Get API Key:</h4>
29+
Go to [https://mandrill.com/signup/](https://mandrill.com/signup/) and *set up a quick FREE acount*. You just got 12,000 emails per month!
30+
31+
After you create an account, *Login*.
32+
33+
(Take note of your login info somewhere.)
34+
35+
__________________________
36+
37+
Open up this link: [Most useful page for getting started with the Ruby Gem](http://help.mandrill.com/entries/23257181-Using-the-Mandrill-Ruby-Gem). This was a good basic look at the Mandrill API send email function with the <code>gem 'madrill-api'</code> which will go in your gem file.</code>
38+
39+
__STEP 1:__ put <code>gem 'madrill-api'</code> in your <code>Gemfile</code>
40+
41+
__STEP 2:__ run bundle install
42+
43+
<pre>
44+
MANDRILL_APIKEY = "alskdfjzixcvxkjzlvc" #test or the #real one
45+
</pre>
46+
47+
<pre>
48+
require 'mandrill'
49+
m = Mandrill::API.new
50+
message = {
51+
:subject=> "Hello from the Mandrill API",
52+
:from_name=> "Your name",
53+
:text=>"Hi message, how are you?",
54+
:to=>[
55+
{
56+
:email=> "recipient@theirdomain.com",
57+
:name=> "Recipient1"
58+
}
59+
],
60+
:html=>"<html>&lt;h1&gt;Hi <strong>message</strong>, how are you?</h1></html>",
61+
:from_email=>"sender@yourdomain.com"
62+
}
63+
sending = m.messages.send message
64+
puts sending
65+
</pre>
66+
67+
[Mandrill: Full Message Calls Documentation](https://mandrillapp.com/api/docs/messages.JSON.html)
68+
69+
[Where to view API Logs](https://mandrillapp.com/settings/api)
70+
71+
__________________________
72+
73+
If you go to the branch in the repo you forked above called <code>$ git checkout final-project;</code>. This is my finished code from this tutorial, so you can check that it is all there compared to your work.

mandrill-tutorial.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'rubygems'
2+
require 'bundler/setup'
3+
require 'sinatra'
4+
require 'sinatra/reloader'
5+
6+
get '/' do
7+
'Welcome to your Penpal app!'
8+
end

0 commit comments

Comments
 (0)