As a course administrator,
So that the right certificate is delivered to a student,
I would like certificates to be emailed to a students registered email address.
Let's start with modifying the certificate_generation.feature by adding the following step:
# features/certificate_generation.feature
...
Then 3 instances of "Certificate" should be created
And 3 certificates should be generated
And 3 images of certificates should be created
And 3 emails with certificates attached should be sent
And I should see "Generated 3 certificates"
...
Run that scenario by pointing cucumber to the line of code where it starts:
Also, add a method called send_email to that module. That method needs to have access to the details hash, so we are going to allow it to take two arguments:
# lib/certificate_generator.rb...defself.send_email(details,file) mail = Mail.newdo from "The course team <#{ENV['GMAIL_ADDRESS']}>" to "#{details[:name]} <#{details[:email]}>" subject "Course Certificate - #{details[:course_name]}" body File.read('pdf/templates/body.txt') add_file filename:"#{PATH}#{file}.pdf",mime_type:'application/x-pdf',content:File.read("#{PATH}#{file}.pdf")end mail.deliverend...
Create a file named body.txt in pdf/templates folder:
$ touch pdf/templates/body.txt
Add some content to that file:
# pdf/templates/body.txt
Hello,
This is your Course Certificate.
Live Long And Prosper!
/The Course Ppl
We could personalize this message, but for now some static content will do.
Another update we need to make is again in the certificate_generator.rb We need to call the send_email method from the generate method in order to actually send the message with the certificate attached to it: