Sending and receiving emails - restarone/violet_rails GitHub Wiki
Violet Rails includes out of the box support for sending and receiving email through Mailgun. Each subdomain name maps to an email address. Eg: help.example.com would have an email address [email protected]
Add these 2 environment variables to (.rbenv-vars in production, .env.test or .env.development). The ingress signing key is used to validate that emails are coming from mailgun
MAILGUN_API_KEY=foo
MAILGUN_INGRESS_SIGNING_KEY=fooQuick reference example: https://github.com/restarone/violet_rails/blob/master/test/plugin_fixtures/billables_report_plugin.yml#L88
subject = "Report of hours logged generated at: #{current_time.strftime("%A, %B #{current_time.day.ordinalize} %Y at%l:%M%p %Z")}"
email_content = <<-HTML
<div class='trix-content'>
<div>Please find the reports of hours logged for different clients listed below;<br><br>
</div>
<ol>
#{generate_email_content_for_clients}
</ol>
</div>
HTML
# Sending email report
email_thread = MessageThread.create!(recipients: [reporting_emails], subject: subject)
email_message = email_thread.messages.create!(
content: email_content.html_safe,
attachments: email_attachments
)use a template instead of manually constructing the HTML and send email templates with dynamically injected segments:
subject = "Support request: #{Time.now.strftime("%A, %B #{Time.now.day.ordinalize} %Y at%l:%M%p %Z")}"
email_content = EmailTemplate.find_by(slug: 'support_request').inject_dynamic_segments({email: api_resource.properties['email'], product: api_resource.properties['product'][0]})
# Sending email report
email_thread = MessageThread.create!(recipients: ['[email protected]'], subject: subject)
email_message = email_thread.messages.create!(
content: email_content.html_safe,
)