zoho_zeptomail-rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/lib/.DS_Store +0 -0
- data/lib/delivery_method.rb +32 -0
- data/lib/railtie.rb +11 -0
- data/lib/zoho_zeptomail/.DS_Store +0 -0
- data/lib/zoho_zeptomail/rails/.DS_Store +0 -0
- data/lib/zoho_zeptomail/rails/master/version.rb +9 -0
- data/lib/zoho_zeptomail/rails/master.rb +12 -0
- data/lib/zoho_zeptomail/rails/version.rb +7 -0
- data/lib/zoho_zeptomail/rails.rb +10 -0
- data/lib/zoho_zeptomail-rails.rb +3 -0
- data/lib/zohozeptomail_mailer.rb +157 -0
- data/sig/.DS_Store +0 -0
- data/sig/zoho_zeptomail/.DS_Store +0 -0
- data/sig/zoho_zeptomail/rails/master.rbs +8 -0
- data/sig/zoho_zeptomail/rails.rbs +6 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f0bf6e9ef49de599fe563889619cf25c9bf0238a880883f2f0f1450635b647a2
|
|
4
|
+
data.tar.gz: 848cadd5d0d147b211bb5f4911503417989997d1adc81cccbd753c75e4e3560d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8d486ca9835a50d60e43e11a28a8f640774162a9db124f41ea661c4ce398449c02b679b1e7bf8c400bdd1057cde0e44d2d05f2470b327a07cd5b90ce35c983e7
|
|
7
|
+
data.tar.gz: e76f5b6ca2c44a789bdd136d2ecd685ef57befb2ea8918e05ef5eb58f2c32f9557cc8acd103554b7f9c07fc4f65509b87f66f8a722addd54d5d2586bb8ad5b2f
|
data/.DS_Store
ADDED
|
Binary file
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
File without changes
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Zoho Corporation Pvt. Ltd.
|
|
4
|
+
All Rights Reserved.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Zoho ZeptoMail Rails
|
|
2
|
+
|
|
3
|
+
### Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gem install zoho_zeptomail-rails
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
You will have to initalize it in your Gem file with `require "zoho_zeptomail-rails"`.
|
|
10
|
+
|
|
11
|
+
1. Use the adapter:
|
|
12
|
+
```ruby
|
|
13
|
+
ActionMailer::Base.delivery_method = :zohozeptomail
|
|
14
|
+
```
|
|
15
|
+
2. `zoho_zeptomail-ruby` gem requires `ZOHO_ZEPTOMAIL_API_KEY_TOKEN` and `ZOHO_ZEPTOMAIL_HOSTED_REGION` environment variable,
|
|
16
|
+
so make sure it's set.
|
|
17
|
+
|
|
18
|
+
## Email
|
|
19
|
+
|
|
20
|
+
### Send an email
|
|
21
|
+
```ruby
|
|
22
|
+
class TestMailer < ActionMailer::Base
|
|
23
|
+
default from: 'michael@zylker.com'
|
|
24
|
+
|
|
25
|
+
def msg(from, to, subject)
|
|
26
|
+
mail(
|
|
27
|
+
from: from,
|
|
28
|
+
to: to,
|
|
29
|
+
subject: subject,
|
|
30
|
+
cc: 'rebeca@zylker.com'
|
|
31
|
+
) do
|
|
32
|
+
|format|
|
|
33
|
+
format.text { render plain: 'hello' }
|
|
34
|
+
format.html { render html: '<div>This is a test email</div>'}
|
|
35
|
+
attachments['filename.pdf'] = File.read('test/mailers/Hello.pdf')
|
|
36
|
+
attachments['text_filename.txt'] = File.read('test/mailers/Hello.txt')
|
|
37
|
+
attachments['image_filename.png'] = File.read('test/mailers/test.png')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class MailerTest < Minitest::Test
|
|
43
|
+
def setup
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_text_message
|
|
47
|
+
TestMailer.msg( 'jerry@zylker.com', 'hello').deliver!
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
```
|
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'railtie'
|
|
3
|
+
require 'zohozeptomail_mailer'
|
|
4
|
+
|
|
5
|
+
module ZohozeptomailRails
|
|
6
|
+
class Mailer
|
|
7
|
+
def initialize(config)
|
|
8
|
+
# No config yet
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Sends the email and returns result
|
|
12
|
+
def deliver(msg)
|
|
13
|
+
ms_msg = RailsMsgToMsMsg.msg_to_ms_msg(msg)
|
|
14
|
+
ms_msg.send
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def settings
|
|
18
|
+
# Define the settings method or use a custom configuration object
|
|
19
|
+
@settings ||= { return_response: true } # Example settings
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def deliver!(msg)
|
|
23
|
+
result = deliver(msg)
|
|
24
|
+
# Ensure result is not nil
|
|
25
|
+
if result.nil? || result.status < 200 || result.status > 204
|
|
26
|
+
puts result
|
|
27
|
+
end
|
|
28
|
+
result
|
|
29
|
+
end
|
|
30
|
+
private
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/railtie.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rails/railtie'
|
|
2
|
+
require 'delivery_method'
|
|
3
|
+
require 'zoho_zeptomail-ruby'
|
|
4
|
+
|
|
5
|
+
module ZohozeptomailRails
|
|
6
|
+
class Railtie < ::Rails::Railtie
|
|
7
|
+
ActiveSupport.on_load(:action_mailer) do
|
|
8
|
+
add_delivery_method :zohozeptomail, ZohozeptomailRails::Mailer
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
require 'cgi'
|
|
2
|
+
|
|
3
|
+
module ZohozeptomailRails
|
|
4
|
+
class RailsMsgToMsMsg
|
|
5
|
+
def self.msg_to_ms_msg(msg)
|
|
6
|
+
ms_msg = ZohoZeptoMail::SendMail.new
|
|
7
|
+
|
|
8
|
+
if msg.from_addrs.empty?
|
|
9
|
+
raise 'From address should not be empty or nil'
|
|
10
|
+
else
|
|
11
|
+
ms_msg.add_from(rails_from_addr(msg.from_addrs))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if msg.subject.empty?
|
|
15
|
+
raise 'Subject should not be empty or nil'
|
|
16
|
+
else
|
|
17
|
+
ms_msg.add_subject(msg.subject)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if msg.to_addrs.empty?
|
|
21
|
+
raise 'Recipients address should not be empty or nil'
|
|
22
|
+
else
|
|
23
|
+
msg.to_addrs.each do |i|
|
|
24
|
+
ms_msg.add_recipients(rails_addr(i))
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
body_text = msg_text(msg) || ""
|
|
29
|
+
body_html = CGI.unescapeHTML(msg_html(msg))
|
|
30
|
+
if body_text != ""
|
|
31
|
+
body_text += '<br>' + body_html
|
|
32
|
+
else
|
|
33
|
+
body_text += body_html
|
|
34
|
+
end
|
|
35
|
+
ms_msg.add_body(body_text)
|
|
36
|
+
|
|
37
|
+
if msg.reply_to
|
|
38
|
+
msg.reply_to.each do |i|
|
|
39
|
+
ms_msg.add_reply_to(rails_addr(i))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
rails_attach(msg.attachments, ms_msg)
|
|
44
|
+
|
|
45
|
+
if msg.cc_addrs
|
|
46
|
+
msg.cc_addrs.each do |i|
|
|
47
|
+
ms_msg.add_cc(rails_addr(i))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if msg.bcc_addrs
|
|
52
|
+
msg.bcc_addrs.each do |i|
|
|
53
|
+
ms_msg.add_bcc(rails_addr(i))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
ms_msg
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def self.rails_attach(attach, ms_msg)
|
|
63
|
+
if !attach.nil?
|
|
64
|
+
attach.each do |attachments|
|
|
65
|
+
ms_msg.add_attachments(content: attachments.body.decoded.to_s, filename: attachments.filename, mime_type: attachments.content_type)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.rails_addr(addr)
|
|
71
|
+
if addr.is_a?(Mail::Address)
|
|
72
|
+
name = addr.name || addr.address
|
|
73
|
+
email = addr.address
|
|
74
|
+
else
|
|
75
|
+
name = nil
|
|
76
|
+
email = addr
|
|
77
|
+
end
|
|
78
|
+
if name.nil?
|
|
79
|
+
{address: email}
|
|
80
|
+
else
|
|
81
|
+
{ name: name, address: email }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def self.rails_from_addr(from_addrs)
|
|
86
|
+
if from_addrs.is_a?(Mail::Address)
|
|
87
|
+
name = from_addrs.name || from_addrs.address
|
|
88
|
+
email = from_addrs.address
|
|
89
|
+
else
|
|
90
|
+
name = nil
|
|
91
|
+
email = from_addrs
|
|
92
|
+
end
|
|
93
|
+
if name.nil?
|
|
94
|
+
{ address: email[0] }
|
|
95
|
+
else
|
|
96
|
+
{ name: name, address: email[0] }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.msg_text(msg)
|
|
101
|
+
text_parts = []
|
|
102
|
+
if msg.multipart?
|
|
103
|
+
msg.parts.each do |part|
|
|
104
|
+
if part.content_type =~ /^multipart\/alternative/i
|
|
105
|
+
text_parts.concat(extract_text_from_multipart_alternative(part))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if msg.mime_type =~ /^text\/plain$/i
|
|
111
|
+
text_parts << msg.body.decoded.to_s.strip
|
|
112
|
+
end
|
|
113
|
+
text_parts.join("<br>") unless text_parts.empty?
|
|
114
|
+
rescue => e
|
|
115
|
+
Rails.logger.error("Error extracting text from email: #{e.message}") if defined?(Rails)
|
|
116
|
+
raise
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def self.extract_text_from_multipart_alternative(part)
|
|
120
|
+
nested_text_parts = []
|
|
121
|
+
part.parts.each do |sub_part|
|
|
122
|
+
if sub_part.content_type =~ /^text\/plain[;$]/i
|
|
123
|
+
nested_text_parts << sub_part.body.decoded.to_s.strip
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
nested_text_parts
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.msg_html(msg)
|
|
130
|
+
html_parts = []
|
|
131
|
+
if msg.multipart?
|
|
132
|
+
msg.parts.each do |part|
|
|
133
|
+
if part.content_type =~ /^multipart\/alternative/i
|
|
134
|
+
html_parts.concat(extract_text_html_multipart_alternative(part))
|
|
135
|
+
elsif part.content_type =~ /^text\/html[;$]/i
|
|
136
|
+
html_parts << part.body.decoded.to_s.strip
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
if msg.mime_type =~ /^text\/html$/i
|
|
141
|
+
html_parts << msg.body.decoded.to_s.strip
|
|
142
|
+
end
|
|
143
|
+
clean_html = html_parts.join("<br>").gsub(/<\/?[^>]*>/, '').strip
|
|
144
|
+
clean_html
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def self.extract_text_html_multipart_alternative(part)
|
|
148
|
+
nested_text_parts = []
|
|
149
|
+
part.parts.each do |sub_part|
|
|
150
|
+
if sub_part.content_type =~ /^text\/html[;$]/i
|
|
151
|
+
nested_text_parts << sub_part.body.decoded.to_s.strip
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
nested_text_parts
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
data/sig/.DS_Store
ADDED
|
Binary file
|
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zoho_zeptomail-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ZohoMail
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-03-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
- zmintegration@zohomail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".DS_Store"
|
|
21
|
+
- ".standard.yml"
|
|
22
|
+
- CHANGELOG.md
|
|
23
|
+
- CODE_OF_CONDUCT.md
|
|
24
|
+
- LICENSE.txt
|
|
25
|
+
- README.md
|
|
26
|
+
- Rakefile
|
|
27
|
+
- lib/.DS_Store
|
|
28
|
+
- lib/delivery_method.rb
|
|
29
|
+
- lib/railtie.rb
|
|
30
|
+
- lib/zoho_zeptomail-rails.rb
|
|
31
|
+
- lib/zoho_zeptomail/.DS_Store
|
|
32
|
+
- lib/zoho_zeptomail/rails.rb
|
|
33
|
+
- lib/zoho_zeptomail/rails/.DS_Store
|
|
34
|
+
- lib/zoho_zeptomail/rails/master.rb
|
|
35
|
+
- lib/zoho_zeptomail/rails/master/version.rb
|
|
36
|
+
- lib/zoho_zeptomail/rails/version.rb
|
|
37
|
+
- lib/zohozeptomail_mailer.rb
|
|
38
|
+
- sig/.DS_Store
|
|
39
|
+
- sig/zoho_zeptomail/.DS_Store
|
|
40
|
+
- sig/zoho_zeptomail/rails.rbs
|
|
41
|
+
- sig/zoho_zeptomail/rails/master.rbs
|
|
42
|
+
homepage: https://www.zoho.com/zeptomail/
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata:
|
|
46
|
+
homepage_uri: https://www.zoho.com/zeptomail/
|
|
47
|
+
source_code_uri: https://github.com/zohomail/zoho_zeptomail-rails/
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 3.1.0
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
requirements: []
|
|
63
|
+
rubygems_version: 3.3.3
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: Zoho ZeptoMail official Ruby SDK
|
|
67
|
+
test_files: []
|