Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few updates including a fix for issue #3 #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/microsoft_actionmailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@ def initialize params
end

def deliver! mail
if mail.html_part.present?
body = mail.html_part.body.encoded
else
body = mail.body.encoded
end

message = ms_create_message(
access_token,
mail.subject,
mail.body.encoded,
mail.to.first
body,
mail.to,
mail.cc,
mail.bcc,
mail.attachments
)

before_send = delivery_options[:before_send]
if before_send && before_send.respond_to?(:call)
before_send.call(mail, message)
end

res = ms_send_message(access_token, message['id'])
ms_send_message(access_token, message['id'])

after_send = delivery_options[:after_send]
if after_send && after_send.respond_to?(:call)
Expand Down
43 changes: 35 additions & 8 deletions lib/microsoft_actionmailer/api.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
module MicrosoftActionmailer
module Api
# Creates a message and saves in 'Draft' mailFolder
def ms_create_message(token, subject, content, address)
def ms_create_message(token, subject, content, to_addresses, cc_addresses, bcc_addresses, attachments)

attachment_list = []
attachments.each do |attachment|
data = { "@odata.type": "#microsoft.graph.fileAttachment",
"name": attachment.filename,
"contentType": attachment.content_type,
"contentBytes": Base64.encode64(attachment.body.raw_source)
}
attachment_list << data
end

to_recipients = []
to_addresses.each do |address|
data = { "emailAddress": { "address": address } }
to_recipients << data
end

cc_recipients = []
cc_addresses.each do |address|
data = { "emailAddress": { "address": address } }
cc_recipients << data
end if cc_addresses.present?

bcc_recipients = []
bcc_addresses.each do |address|
data = { "emailAddress": { "address": address } }
bcc_recipients << data
end if bcc_addresses.present?

query = {
"subject": subject,
"importance": "Normal",
"body":{
"contentType": "HTML",
"content": content
},
"toRecipients": [
{
"emailAddress": {
"address": address
}
}
]
"toRecipients": to_recipients,
"ccRecipients": cc_recipients,
"bccRecipients": bcc_recipients,
"attachments": attachment_list
}

create_message_url = '/v1.0/me/messages'
req_method = 'post'
response = make_api_call create_message_url, token, query,req_method
Expand Down
2 changes: 1 addition & 1 deletion lib/microsoft_actionmailer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MicrosoftActionmailer
VERSION = "0.2.0"
VERSION = "0.4.1"
end