isomorfeus-mailer 1.0.0.zeta17

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52d9bd4e04bd1cdc98d6f4e554c60157d8e957696c893b3ad7c1d1ae270e04c4
4
+ data.tar.gz: '093267ef78db9fbe97e3e615d9504cd6c1d88ff005da48c8177539e300d4db20'
5
+ SHA512:
6
+ metadata.gz: a6c97e10fa49fd702df741a53dd47e2056af9b989e141c6f2d76367626e57fc042d64abd0b6c252498b70dcf675cb49fc4625ef3714104a505402be7f4c30ffa
7
+ data.tar.gz: 0f3161bce4725cb4473f0cc7c4c8e3ecac7e281d3dd9b71102a5f2b211bbd2cdb52215f3644481751eafdd521ca3630fffac721698f9ddd8e30601ac7d438b1d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2019 Jan Biedermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,93 @@
1
+ # isomorfeus-mailer
2
+
3
+ Build mails with components and send them with [Mailhandler](https://github.com/wildbit/mailhandler#email-sending).
4
+
5
+ ### Community and Support
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
+
8
+ ### Configuration
9
+
10
+ Configuration options can be set as hash passed to:
11
+ ```ruby
12
+ Isomorfeus.email_sender_config = { type: :smtp }
13
+ ```
14
+ All configuration options of Mailhandler can be passed in the hash. For Mailhandler option see
15
+ [Email sending](https://github.com/wildbit/mailhandler#email-sending) section of the Mailhandler docs.
16
+
17
+ ### Usage
18
+
19
+ #### Mail Components
20
+ Within a isomorfeus project components for building emails are the app/mail_components directory.
21
+ When using LucidComponent or LucidMaterial::Component the main component passed to the mail must be either a LucidApp or LucidMaterial::App component.
22
+ Each mail template build of components can be considered a tiny App.
23
+
24
+ Mail components are rendered using the React static renderer, so the React rules for static rendering apply.
25
+
26
+ Inline styles work in Mail Components too.
27
+
28
+ Example component:
29
+ ```ruby
30
+ class EmailComponent < LucidApp::Base
31
+ # the toplevel component must be a App component
32
+ # then oder LucidComponent's can be used in the render block
33
+
34
+ prop :name
35
+
36
+ render do
37
+ DIV "Welcome #{props.name}!"
38
+ end
39
+ end
40
+ ```
41
+
42
+ #### Sending Mail
43
+
44
+ One class is provided to actually build and send the mail: LucidMail. This class is only available on the server.
45
+
46
+ Sending mail with the rendered component:
47
+ ```ruby
48
+ mail = LucidMail.new(component: 'EmailComponent',
49
+ props: { name: 'Siegfried' }, # are passed to the component
50
+ from: 'me@test.com',
51
+ to: 'you@test.com',
52
+ subject: 'Welcome')
53
+ mail.send
54
+ ```
55
+ #### Inspecting the rendered component
56
+
57
+ The generated HTML is accessible after building the mail using:
58
+ ```ruby
59
+ mail.build
60
+ html = mail.rendered_component
61
+ ```
62
+
63
+ #### Accessing the mail before sending
64
+
65
+ It is possible to access the actual mail object after building it for further inspection or modification:
66
+ ```ruby
67
+ mail.build
68
+ mail_object = mail.mail
69
+ ```
70
+ For documentation about the Mail Object see the [Mail Documentation](https://github.com/mikel/mail).
71
+
72
+ #### Triggering mail from a client
73
+ LucidMail is available only on the server. It can be wrapped in a operation to allow triggering the sending of mail from a client. Example:
74
+ ```ruby
75
+ class MailOp < LucidQuickOp::Base
76
+ op do
77
+ LucidMail.new(component: 'EmailComponent',
78
+ from: 'me@test.com',
79
+ to: current_user.email,
80
+ subject: 'Welcome')
81
+ end
82
+ end
83
+ ```
84
+ Make sure policy allows running the operation:
85
+ ```ruby
86
+ class MyUserPolicy
87
+ allow MailOp, :promise_run
88
+ end
89
+ ```
90
+ Then on a client mail can be triggered:
91
+ ```ruby
92
+ MailOp.promise_run
93
+ ```
@@ -0,0 +1,5 @@
1
+ require 'html2text'
2
+ require 'mailhandler'
3
+ require 'isomorfeus-react'
4
+ require 'isomorfeus/mailer/config'
5
+ require 'lucid_mail'
@@ -0,0 +1,23 @@
1
+ module Isomorfeus
2
+ # available settings
3
+ class << self
4
+ if RUBY_ENGINE != 'opal'
5
+ def email_sender_config
6
+ @email_sender_config ||= { type: :smtp }
7
+ end
8
+
9
+ def email_sender_config=(new_config)
10
+ Isomorfeus.raise_error "email_sender_config must at least include a :type!" unless new_config.key?(:type)
11
+ @email_sender_config = new_config
12
+ end
13
+
14
+ def email_sender
15
+ @email_sender ||= MailHandler.sender(Isomorfeus.email_sender_config[:type]) do |dispatcher|
16
+ Isomorfeus.email_sender_config.each do |key, value|
17
+ dispatcher.__send__("#{key}=".to_sym, value) unless key == :type
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Isomorfeus
2
+ module Mailer
3
+ VERSION = '1.0.0.zeta17'
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ class LucidMail
2
+ include Isomorfeus::ReactViewHelper
3
+ extend LucidPropDeclaration::Mixin
4
+
5
+ prop :from, class: String, required: true
6
+ prop :reply_to, class: String, required: false
7
+ prop :to, class: String, required: true
8
+ prop :subject, class: String, required: true
9
+ prop :component, class: String, required: true
10
+ prop :props
11
+
12
+ attr_reader :mail
13
+ attr_reader :props
14
+ attr_reader :rendered_component
15
+
16
+ def initialize(**props)
17
+ self.class.validate_props(props)
18
+ @props = LucidProps.new(props)
19
+ @mail = nil
20
+ @rendered_component = nil
21
+ end
22
+
23
+ def render_component
24
+ rendered_tree = mount_static_component(props.component, props.props, 'mail_components.js')
25
+ @rendered_component = <<~HTML
26
+ <!DOCTYPE html>
27
+ <html><head><style type="text/css">#{ssr_styles}</style></head><body>#{rendered_tree}</body></html>
28
+ HTML
29
+ self
30
+ end
31
+
32
+ def build
33
+ render_component unless rendered_component
34
+ html_body = rendered_component
35
+ text_body = Html2Text.convert(rendered_component)
36
+ @mail = Mail.new
37
+ @mail.to(props.to)
38
+ @mail.from(props.from)
39
+ @mail.subject(props.subject)
40
+ @mail.reply_to(props.reply_to) if props.key?(:reply_to)
41
+ @mail.text_part do
42
+ content_type 'text/plain; charset=UTF-8'
43
+ body text_body
44
+ end
45
+ @mail.html_part do
46
+ content_type 'text/html; charset=UTF-8'
47
+ body html_body
48
+ end
49
+ self
50
+ end
51
+
52
+ def send
53
+ build unless mail
54
+ Isomorfeus.email_sender.send_email(mail)
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isomorfeus-mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.zeta17
5
+ platform: ruby
6
+ authors:
7
+ - Jan Biedermann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: html2text
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mailhandler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.10.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: opal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: opal-activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: isomorfeus-react
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 16.12.18
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 16.12.18
111
+ - !ruby/object:Gem::Dependency
112
+ name: isomorfeus-redux
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 4.0.17
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 4.0.17
125
+ - !ruby/object:Gem::Dependency
126
+ name: isomorfeus
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0.zeta17
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.0.zeta17
139
+ - !ruby/object:Gem::Dependency
140
+ name: opal-webpack-loader
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.10
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.10
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 3.8.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 3.8.0
181
+ description: Write mail template components and send mail.
182
+ email: jan@kursator.de
183
+ executables: []
184
+ extensions: []
185
+ extra_rdoc_files: []
186
+ files:
187
+ - LICENSE
188
+ - README.md
189
+ - lib/isomorfeus-mailer.rb
190
+ - lib/isomorfeus/mailer/config.rb
191
+ - lib/isomorfeus/mailer/version.rb
192
+ - lib/lucid_mail.rb
193
+ homepage: http://isomorfeus.com
194
+ licenses:
195
+ - MIT
196
+ metadata:
197
+ github_repo: ssh://github.com/isomorfeus/gems
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">"
210
+ - !ruby/object:Gem::Version
211
+ version: 1.3.1
212
+ requirements: []
213
+ rubygems_version: 3.0.6
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: Write mail template components and send mail.
217
+ test_files: []