The official AlphaMail Ruby gem
Description
This gem is the official client library for sending transactional emails with the cloud service AlphaMail. To use this service you need an account. You can sign up for an free account on our website (www.comfirm.se).
This is not a service for sending SPAM, newsletters or bulk emails of any kind. This is for transactional emails exclusive. Read more about transactional emails on www.comfirm.se.
Installation
This gem requires json:
# gem install json
Now, install alphamail:
# gem install alphamail
Usage
First you need to require alphamail:
require 'rubygems'
require 'alphamail'
Create the payload:
myPayload = AlphaMail::MessagePayload.new
Now, set the fields:
# Set payload fields
myPayload.project_id = 139
myPayload.receiver_id = 1
myPayload.sender.name = 'Jack Sender'
myPayload.sender.email = '[email protected]'
myPayload.receiver.name = 'John Doe'
myPayload.receiver.email = '[email protected]'
myPayload.body = myMember
Where myPayload.body is the object that will be insertet into the email template. Make sure that the class has implemented the to_json method.
Setup the service:
myService = AlphaMail::EmailService.new 'http://api.amail.io/v1', 'YOUR-TOKEN-HERE'
Replace YOUR-TOKEN-HERE with a valid token. You can crate new tokens at the dashboard under settings.
Now it’s time for magic:
am_res = myService.queue(myPayload)
Send the payload by calling queue. The respond object will be stored in am_res as showed above.
Shorthand example:
require ‘rubygems’ require ‘alphamail’
class NewMember attr_accessor :name attr_accessor :password def initialize(name = ‘Unknown’, password = ‘unset1’) @name = name @password = password end def to_json(*a) { ‘name’ => name, ‘password’ => password }.to_json(*a) end end
myService = AlphaMail::EmailService.new ‘api.amail.io/v1’, ‘YOUR-TOKEN-HERE’
am_res = myService.queue(AlphaMail::MessagePayload.new( 139, # Project ID 2, # Sender ID AlphaMail::Contact.new(‘Jack Sender’, ‘[email protected]’), # Sender AlphaMail::Contact.new(‘John Doe’, ‘[email protected]’), # Receiver NewMember.new(‘John Doe’, ‘wh4tswhAt’) # Body object )) puts “#am_resam_res.error_code #am_resam_res.message”
Error codes
The respond will be returned as an AlphaMailError object. The AlphaMailError class contains following fields:
error_code
Possible values for error_code:
-
0 OK
-
-1 Something went wrong
-
-2 Something else
Author
Jack Engqvist Johansson <[email protected]>
License
BSD 3-clause, see the LICENSE file included in the source distribution.
Download
The latest version of this library can be downloaded at
Online Documentation should be located at