This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
forked from codeforamerica/workforwardnola
-
Notifications
You must be signed in to change notification settings - Fork 3
README updates, Job System Form Update: AWS SES, S3 #53
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
86bf26f
AWS emailer system in early stages
tmloupe b99084e
Added in validation for emails, added redirect to contacts, and added…
tmloupe fa727e4
Update readme and redirect
tmloupe 81d4092
Code quality changes and updated .env.example
tmloupe f9804a8
Implemented AWS S3 for file storage. Additionally updates readmes for…
tmloupe bcb5248
Updated wording for accessibility on both index and the job form.
tmloupe 486bd21
Edited file i/o and revised emailer logic
tmloupe b97666d
Switched to Raw Emails for sending attachments. additionally handles …
tmloupe 4155711
Fixed gems
tmloupe 694b1df
Fixed gems 2.0
tmloupe 64bcbd5
Merge pull request #59 from loyno-mathcs/aws-attachment
tmloupe 3bb3667
Merge branch 'master' into aws-ses
tmloupe 899574b
Finished the emailer system, updated READMES, squashed bug, and incre…
tmloupe b5afbfb
Rubocop
tmloupe dd37066
Add default Rake task and .travis.yml file so Travis CI stops complai…
9a1bae7
Fixed careers -> job system button
tmloupe ca6a261
Merge branch 'aws-ses' of https://github.com/loyno-mathcs/workforward…
tmloupe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,10 @@ EMAIL_PORT=587 | |
[email protected] | ||
EMAIL_PASSWORD=chat_this_password | ||
EMAIL_DOMAIN=mynonprofit.org | ||
|
||
[email protected] | ||
[email protected] | ||
|
||
AWS_ACCESS=aws_access_key | ||
AWS_SECRET=aws_secret_key | ||
AWS_BUCKET=aws_bucket_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.5 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'aws-sdk-ses' # v2: require 'aws-sdk' | ||
require './emailer.rb' | ||
require 'dotenv' | ||
require 'mime' | ||
|
||
module WorkForwardNola | ||
# Class for sending out emails through AWS | ||
class AwsEmailer < Emailer | ||
Dotenv.load | ||
|
||
def initialize(access, secret) | ||
Aws.config.update(credentials: Aws::Credentials.new(access, secret), region: 'us-east-1') | ||
@ses = Aws::SES::Client.new | ||
rescue Aws::SES::Errors::ServiceError => error | ||
throw Aws::SES::Errors::ServiceError.new("Error configuring AWS SES client. Error message: #{error}") | ||
end | ||
|
||
def send_email(recipients, sender, subject, text_body, html_body, | ||
attachment_name = nil, attachment_file = nil) | ||
recipients = cc if recipients.nil? | ||
msg_mixed = MIME::Multipart::Mixed.new | ||
unless attachment_file.nil? | ||
attachment = MIME::Application.new(Base64.encode64(open(attachment_file, 'rb').read)) | ||
attachment.transfer_encoding = 'base64' | ||
attachment.disposition = 'attachment' | ||
msg_mixed.attach(attachment, 'filename' => attachment_name) | ||
end | ||
msg_body = MIME::Multipart::Alternative.new | ||
msg_body.add(MIME::Text.new(text_body, 'plain')) | ||
msg_body.add(MIME::Text.new(html_body, 'html')) | ||
msg_mixed.add(msg_body) | ||
msg = MIME::Mail.new(msg_mixed) | ||
msg.subject = subject | ||
# Try to send the email. | ||
begin | ||
# Verify the emails, this will add them to the verified emails | ||
# if using sandboxes. | ||
|
||
# check_emails sender | ||
# check_emails recipient | ||
# check_emails cc | ||
# check_emails bcc | ||
# check_emails reply_to | ||
|
||
# Provide the contents of the email. | ||
|
||
resp = @ses.send_raw_email( | ||
source: sender, | ||
destinations: recipients, | ||
raw_message: { | ||
data: msg.to_s | ||
} | ||
) | ||
|
||
puts "Email sent to #{recipients.inspect}: #{resp.inspect}" | ||
rescue Aws::SES::Errors::ServiceError => error | ||
# If something goes wrong, display an error message. | ||
throw error | ||
end | ||
end | ||
|
||
private | ||
|
||
# Used to verify emails for use in AWS sandbox environment | ||
def check_emails(emails) | ||
return if emails.nil? | ||
if emails.respond_to? :each | ||
emails.each { |e| @ses.verify_email_identity email_address: e } | ||
else | ||
@ses.verify_email_identity email_address: emails | ||
end | ||
end | ||
|
||
def as_email_array(emails) | ||
return emails if emails.respond_to? :each | ||
[emails] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis still needs some config. Likely a dummy
.env
file that matches what it's supposed to do to setup the database for testing.