azure_communication_email 0.1.0 → 0.2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e13809a220b8a5a263414d0b53618afb1ed9006d576d9df3bc784b766e3c6faf
|
4
|
+
data.tar.gz: 1cf7750c4545e6dfe01c756a950212387e771a080345532b9cdf368bed4fe548
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda943ef50229a34293a1c0b87fc9b99835c6279c863a5f4857dc6adbbb2c88bec93596751e59cdb55c17ca25949c223cb27c551ce1e96d7c02976928f029761
|
7
|
+
data.tar.gz: ee436d8da33038971b9491568a2794420b448662a5086f5a4164fca2ca80fdb2bd10ddff6979e0e96362f64e3ad7f8e9454e1e1147fc3574dac0dc45b562d64f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Azure Communication Email
|
2
2
|
|
3
|
-
Azure Communication Email is an Action Mailer delivery method for Ruby on Rails using the Azure
|
3
|
+
Azure Communication Email is an Action Mailer delivery method for Ruby on Rails using the [Azure Email Communications Service](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/create-email-communication-resource?pivots=platform-azp).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -26,12 +26,28 @@ To send emails using Azure Communication Services, configure Action Mailer with
|
|
26
26
|
Rails.application.configure do
|
27
27
|
config.action_mailer.delivery_method = :azure_communication_email
|
28
28
|
config.action_mailer.azure_communication_email_settings = {
|
29
|
-
endpoint: ENV.fetch("ACS_EMAIL_ENDPOINT"),
|
29
|
+
endpoint: ENV.fetch("ACS_EMAIL_ENDPOINT"), # e.g., "https://<RESOURCE_NAME>.communication.azure.com"
|
30
30
|
access_key: ENV.fetch("ACS_EMAIL_ACCESS_KEY"),
|
31
31
|
}
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
Then, you can use Action Mailer as usual:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class UserMailer < ApplicationMailer
|
39
|
+
def welcome_email(user)
|
40
|
+
@user = user
|
41
|
+
mail(to: @user.email, from: "donotreply@<yourdomain>.com", subject: "Hello World!")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
## Links
|
47
|
+
|
48
|
+
- [Service limits for Azure Communication Services](https://learn.microsoft.com/en-us/azure/communication-services/concepts/service-limits#email)
|
49
|
+
- [How to add and remove Multiple Sender Addresses to Email Communication Service](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/add-multiple-senders?pivots=platform-azp)
|
50
|
+
|
35
51
|
## Contributing
|
36
52
|
|
37
53
|
Bug reports and pull requests are welcome.
|
@@ -12,32 +12,44 @@ module AzureCommunicationEmail
|
|
12
12
|
|
13
13
|
def as_json
|
14
14
|
hash = {
|
15
|
-
"senderAddress" =>
|
15
|
+
"senderAddress" => first_sender_address,
|
16
16
|
"content" => {
|
17
17
|
"subject" => @mail.subject.to_s,
|
18
18
|
"plainText" => plain_text_body
|
19
19
|
},
|
20
20
|
"recipients" => {
|
21
|
-
"to" => recipient_objects(
|
21
|
+
"to" => recipient_objects(:to)
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# Does only work with custom domains
|
26
|
+
if (name = first_sender_display_name).present?
|
27
|
+
hash["senderDisplayName"] = name
|
28
|
+
end
|
29
|
+
|
30
|
+
if (html = html_body).present?
|
31
|
+
hash["content"]["html"] = html
|
32
|
+
end
|
27
33
|
|
28
|
-
cc
|
29
|
-
|
30
|
-
|
31
|
-
hash["recipients"]["bcc"] = bcc if bcc.present?
|
34
|
+
if (cc = recipient_objects(:cc)).present?
|
35
|
+
hash["recipients"]["cc"] = cc
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
if (bcc = recipient_objects(:bcc)).present?
|
39
|
+
hash["recipients"]["bcc"] = bcc
|
40
|
+
end
|
41
|
+
|
42
|
+
if (reply_to = recipient_objects(:reply_to)).present?
|
43
|
+
hash["replyTo"] = reply_to
|
44
|
+
end
|
35
45
|
|
36
|
-
headers = custom_headers
|
37
|
-
|
46
|
+
if (headers = custom_headers).present?
|
47
|
+
hash["headers"] = headers
|
48
|
+
end
|
38
49
|
|
39
|
-
attachments = attachment_objects
|
40
|
-
|
50
|
+
if (attachments = attachment_objects).present?
|
51
|
+
hash["attachments"] = attachments
|
52
|
+
end
|
41
53
|
|
42
54
|
hash
|
43
55
|
end
|
@@ -49,23 +61,61 @@ module AzureCommunicationEmail
|
|
49
61
|
private
|
50
62
|
|
51
63
|
def plain_text_body
|
52
|
-
if @mail.text_part
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
64
|
+
return extract_text_part if @mail.text_part
|
65
|
+
return extract_plain_body if @mail.mime_type.to_s.start_with?("text/plain")
|
66
|
+
return extract_bare_body if @mail.mime_type.to_s.blank?
|
67
|
+
|
68
|
+
"" # HTML-only message
|
57
69
|
end
|
58
70
|
|
59
71
|
def html_body
|
60
|
-
@mail.html_part
|
72
|
+
return extract_html_part if @mail.html_part
|
73
|
+
return extract_html_body if @mail.mime_type.to_s.start_with?("text/html")
|
74
|
+
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def extract_text_part
|
79
|
+
@mail.text_part.body.decoded.to_s
|
61
80
|
end
|
62
81
|
|
63
|
-
def
|
64
|
-
|
82
|
+
def extract_plain_body
|
83
|
+
@mail.body.decoded.to_s
|
65
84
|
end
|
66
85
|
|
67
|
-
def
|
68
|
-
|
86
|
+
def extract_bare_body
|
87
|
+
@mail.body&.decoded.to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
def extract_html_part
|
91
|
+
@mail.html_part.body.decoded.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def extract_html_body
|
95
|
+
@mail.body.decoded.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
def address_list(field_sym)
|
99
|
+
field = @mail[field_sym]
|
100
|
+
return [] unless field.respond_to?(:addrs)
|
101
|
+
field.addrs
|
102
|
+
end
|
103
|
+
|
104
|
+
def first_sender_address
|
105
|
+
address_list(:from).first&.address.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def first_sender_display_name
|
109
|
+
address_list(:from).first&.display_name.to_s.strip
|
110
|
+
end
|
111
|
+
|
112
|
+
def recipient_objects(field_sym)
|
113
|
+
address_list(field_sym).map do |addr|
|
114
|
+
obj = { "address" => addr.address.to_s }
|
115
|
+
name = addr.display_name.to_s.strip
|
116
|
+
obj["displayName"] = name if name.present?
|
117
|
+
obj
|
118
|
+
end
|
69
119
|
end
|
70
120
|
|
71
121
|
def attachment_objects
|
@@ -84,8 +134,8 @@ module AzureCommunicationEmail
|
|
84
134
|
return {} unless @mail.header
|
85
135
|
|
86
136
|
@mail.header.fields
|
87
|
-
|
88
|
-
|
137
|
+
.select { |field| field.name =~ /\AX-/i }
|
138
|
+
.to_h { |field| [ field.name, field.value.to_s ] }
|
89
139
|
end
|
90
140
|
end
|
91
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure_communication_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devran Cosmo Uenal
|
@@ -65,8 +65,7 @@ dependencies:
|
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '2.8'
|
68
|
-
description: Action Mailer delivery method using the Azure
|
69
|
-
Email API.
|
68
|
+
description: Action Mailer delivery method using the Azure Email Communications Service.
|
70
69
|
email:
|
71
70
|
- maccosmo@gmail.com
|
72
71
|
executables: []
|
@@ -105,5 +104,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
104
|
requirements: []
|
106
105
|
rubygems_version: 3.7.1
|
107
106
|
specification_version: 4
|
108
|
-
summary: Azure
|
107
|
+
summary: Azure Email Communications Service Delivery Method for Action Mailer
|
109
108
|
test_files: []
|