Module: Jangosmtp

Defined in:
lib/jangosmtp.rb,
lib/jangosmtp/version.rb

Constant Summary collapse

BASE_URL =
'http://api.jangomail.com/api.asmx/'
VERSION =
"0.1.2.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auto_generate_plainObject

Returns the value of attribute auto_generate_plain.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def auto_generate_plain
  @auto_generate_plain
end

.click_trackingObject

Returns the value of attribute click_tracking.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def click_tracking
  @click_tracking
end

.max_attemptsObject

Returns the value of attribute max_attempts.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def max_attempts
  @max_attempts
end

.open_trackingObject

Returns the value of attribute open_tracking.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def open_tracking
  @open_tracking
end

.passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def password
  @password
end

.usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/jangosmtp.rb', line 8

def username
  @username
end

Class Method Details

.create_group(group_name) ⇒ Object

Create a group and return the successfull value group_name: group name that the user wants to get the id for, should only contain alphanumeric ( and spaces )

will be cleaned if an incorrect name is used


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jangosmtp.rb', line 61

def create_group( group_name )
  check_user_pass
  # First we need to clean the group_name since jangosmtp only allows alphanumeric characters
  group_name.tr!('^A-Za-z0-9 ', '')
  options = {
    'Username' => @username,
    'Password' => @password,
    'GroupName' => group_name
  }

  response = post_with_attempts( 'AddTransactionalGroup', options )
  if response != false
    new_group_id = Nokogiri::XML.parse(response.body).xpath("*").first.content.split("\n")[2]
  end
  return new_group_id
end

.get_create_group(group_name) ⇒ Object

Get a group if the group exists, otherwise create a group using a group name and return it’s id group_name: group name that the user wants to get the id for, should only contain alphanumeric ( and spaces )

will be cleaned if an incorrect name is used


23
24
25
26
27
28
29
30
31
# File 'lib/jangosmtp.rb', line 23

def get_create_group( group_name )
  check_user_pass
  existing_group_id = get_group_id( group_name )
  if existing_group_id == nil
    new_group_id = create_group( group_name )
    return new_group_id
  end
  return existing_group_id
end

.get_group_id(group_name) ⇒ Object

Get the id of a requested group group_name: group name that the user wants to get the id for, should only contain alphanumeric ( and spaces )

will be cleaned if an incorrect name is used


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jangosmtp.rb', line 36

def get_group_id( group_name )
  check_user_pass
  # First we need to clean the group_name since jangosmtp only allows alphanumeric characters
  group_name.tr!('^A-Za-z0-9 ', '')
  options = {
    'Username' => @username,
    'Password' => @password,
    'GroupName' => group_name
  }

  # First we are going to check the existing groups to make sure that the current group doesn't already exist.
  found_group = false
  existing_group_id = nil
  response = post_with_attempts( "GetTransactionalGroupID", options )
  if response != false
    existing_group_id = Nokogiri::XML.parse(response.body).xpath("*").first.content.split("\n")[2]
    found_group = true
  end

  return existing_group_id
end

.options(hash) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/jangosmtp.rb', line 11

def options( hash )
  @username = hash[:username] if !hash[:username].nil?
  @password = hash[:password] if !hash[:password].nil?
  @max_attempts = hash[:max_attempts] ||= 1
  @click_tracking = hash[:click_tracking] ||= true
  @open_tracking = hash[:open_tracking] ||= true
  @auto_generate_plain = hash[:open_tracking] ||= true
end

.send_email(group_name, subject, to_email, from_email, from_name, html) ⇒ Object

Send an email and get/create a requested group group_name: group name that the user wants the email to be applied to, should only contain alphanumeric

( and spaces ) will be cleaned if an incorrect name is used

subject: the subject of the email to be sent to_email: the single email address that the email will be sent to from_email: the email address that the email will be coming from from_name: the name that the email address will be coming from html: the html of the email message to be sent

IMPORTANT: This function will attempt to get or create a group for each email that is sent. If you will

be sending a lot of emails to the same group I would recommend you create the group first and use
the send_email_with_group_id function since that takes a group_id and won't attempt to create the
group with each email that is sent


91
92
93
94
95
96
97
# File 'lib/jangosmtp.rb', line 91

def send_email( group_name, subject, to_email, from_email, from_name, html )
  check_user_pass
  group_id = get_create_group( group_name )
  unless group_id.nil?
    return send_email_with_group_id( group_id, subject, to_email, from_email, from_name, html )
  end
end

.send_email_with_group_id(group_id, subject, to_email, from_email, from_name, html) ⇒ Object

Send an email using a pre-existing group group_id: the id of the group that this email will be applied to subject: the subject of the email to be sent to_email: the single email address that the email will be sent to from_email: the email address that the email will be coming from from_name: the name that the email address will be coming from html: the html of the email message to be sent



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/jangosmtp.rb', line 106

def send_email_with_group_id( group_id, subject, to_email, from_email, from_name, html )
  check_user_pass
  options = {
    'Username' => @username,
    'Password' => @password,
    'FromEmail' => from_email,
    'FromName' => from_name,
    'ToEmailAddress' => to_email,
    'Subject' => subject,
    'MessagePlain' => 'auto-generate',
    'MessageHTML' => html,
    'Options' => 'OpenTrack=' + @open_tracking.to_s + ',ClickTrack=' + @click_tracking.to_s + ',TransactionalGroupID=' + group_id
  }
  return post_with_attempts( 'SendTransactionalEmail', options )
end