From 56dc312006c98cc82da750737786b792f5685b38 Mon Sep 17 00:00:00 2001 From: ShounakB <65479699+Shounaks@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:40:03 +0530 Subject: [PATCH] Adding AWS SES Support To Emails. --- Gemfile | 3 +++ app/mailers/aws_ses_integrated_mailer.rb | 29 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 app/mailers/aws_ses_integrated_mailer.rb diff --git a/Gemfile b/Gemfile index 44f811806..4dc5ab30b 100644 --- a/Gemfile +++ b/Gemfile @@ -112,3 +112,6 @@ gem 'shellwords' # PDF reader for validating PDF file submissions gem 'pdf-reader' + +#panopto auth +gem 'aws-sdk-ses' \ No newline at end of file diff --git a/app/mailers/aws_ses_integrated_mailer.rb b/app/mailers/aws_ses_integrated_mailer.rb new file mode 100644 index 000000000..a849f0d62 --- /dev/null +++ b/app/mailers/aws_ses_integrated_mailer.rb @@ -0,0 +1,29 @@ +require 'aws-sdk-ses' # v2: require 'aws-sdk' + +def use_ses_for_mail(sender, recipient, subject, htmlbody, textbody, encoding){ + ses = Aws::SES::Client.new(region: '') + begin + ses.send_email( + destination: {to_addresses: [recipient]}, message: { + body: { + html: { + charset: encoding, + data: htmlbody + }, + text: { + charset: encoding, + data: textbody + } + }, + subject: { + charset: encoding, + data: subject + } + }, source: sender + ) + + puts "Email sent to #{recipient}" + rescue Aws::SES::Errors::ServiceError => e + puts "Email not sent. Error message: #{e}" + end +} \ No newline at end of file