isomorfeus-mailer 1.0.0.zeta15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b26d6d0928ff4e536975dd5622127805e3e0cd1a428165bf188f21002447a6f
4
+ data.tar.gz: ac146fa28b1ded3a142197b1a113b4a1772c8d914160d2e940d68506ba13d8ce
5
+ SHA512:
6
+ metadata.gz: bf3a5c0ec0cc3b62c0bb454c120aed8537a9209459fa912688efb1b6c564fdd4e155ab7357afa4512bb1340c347168638b690e6b119c86f0cfb31b94aaecef7f
7
+ data.tar.gz: 8b2daf307f5e03662d51be48e248c7ed0af094a11e6977b793823d2fc6ab6c8384d0a053f14ddf94879e76665c2dd03c499f0cab1ef08d66bb7aecb164eb6933
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,69 @@
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
+ Within a isomorfeus project components for building emails are the app/mail_components directory.
20
+ When using LucidComponent or LucidMaterial::Component the main component passed to the mail must be either a LucidApp or LucidMaterial::App component.
21
+
22
+ One class is provided to actually build and send the mail: LucidMail. This class is only available on the server.
23
+
24
+ Example component:
25
+ ```ruby
26
+ class EmailComponent < LucidApp::Base
27
+ # the toplevel component must be a App component
28
+ # then oder LucidComponent's can be used in the render block
29
+
30
+ prop :name
31
+
32
+ render do
33
+ DIV "Welcome #{props.name}!"
34
+ end
35
+ end
36
+ ```
37
+
38
+ Sending mail with the rendered component:
39
+ ```ruby
40
+ mail = LucidMail.new(component: 'EmailComponent',
41
+ props: { name: 'Siegfried' }, # are passed to the component
42
+ from: 'me@test.com',
43
+ to: 'you@test.com',
44
+ subject: 'Welcome')
45
+ mail.send
46
+ ```
47
+
48
+ #### Triggering mail from a client
49
+ 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:
50
+ ```ruby
51
+ class MailOp < LucidQuickOp::Base
52
+ op do
53
+ LucidMail.new(component: 'EmailComponent',
54
+ from: 'me@test.com',
55
+ to: current_user.email,
56
+ subject: 'Welcome')
57
+ end
58
+ end
59
+ ```
60
+ Make sure policy allows running the operation:
61
+ ```ruby
62
+ class MyUserPolicy
63
+ allow MailOp, :promise_run
64
+ end
65
+ ```
66
+ Then on a client mail can be triggered:
67
+ ```ruby
68
+ MailOp.promise_run
69
+ ```
@@ -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,26 @@
1
+ module Isomorfeus
2
+ # available settings
3
+ class << self
4
+ if RUBY_ENGINE == 'opal'
5
+ # nothing
6
+ else
7
+
8
+ def email_sender_config
9
+ @email_sender_config ||= { type: :smtp }
10
+ end
11
+
12
+ def email_sender_config=(new_config)
13
+ Isomorfeus.raise_error "email_sender_config must at least include a :type!" unless new_config.key?(:type)
14
+ @email_sender_config = new_config
15
+ end
16
+
17
+ def email_sender
18
+ @email_sender ||= MailHandler.sender(Isomorfeus.email_sender_config[:type]) do |dispatcher|
19
+ Isomorfeus.email_sender_config.each do |key,value|
20
+ dispatcher.send("#{key}=".to_sym, value)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Isomorfeus
2
+ module Mailer
3
+ VERSION = '1.0.0.zeta15'
4
+ end
5
+ end
@@ -0,0 +1,57 @@
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
+ STDERR.puts "props: #{props.to_h}"
25
+ rendered_tree = mount_static_component(props.component, props.props, 'mail_components.js')
26
+ @rendered_component = <<~HTML
27
+ <!DOCTYPE html>
28
+ <html><head><style type="text/css">#{ssr_styles}</style></head><body>#{rendered_tree}</body></html>
29
+ HTML
30
+ self
31
+ end
32
+
33
+ def build
34
+ render_component unless rendered_component
35
+ html_body = rendered_component
36
+ text_body = Html2Text.convert(rendered_component)
37
+ @mail = Mail.new
38
+ @mail.to(props.to)
39
+ @mail.from(props.from)
40
+ @mail.subject(props.subject)
41
+ @mail.reply_to(props.reply_to) if props.key?(:reply_to)
42
+ @mail.text_part do
43
+ content_type 'text/plain; charset=UTF-8'
44
+ body text_body
45
+ end
46
+ @mail.html_part do
47
+ content_type 'text/html; charset=UTF-8'
48
+ body html_body
49
+ end
50
+ self
51
+ end
52
+
53
+ def send
54
+ build unless mail
55
+ Isomorfeus.email_sender.send_email(mail)
56
+ end
57
+ 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.zeta15
5
+ platform: ruby
6
+ authors:
7
+ - Jan Biedermann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-10 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.17
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.17
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.zeta15
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.zeta15
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: []