Sending Email from CM Admin 📧
Overview
The CM Admin email feature allows to send emails directly from the CM Admin. This documentation outlines how to use the CM Admin emails, including its configuration and examples.
Usage
To user CM Admin email use the CmAdmin.send_email
method.
Attributes
-
from
(optional) -
Specify from whom mail should be delivered. Takes only string.
-
If not specified, it will use the default from email from the project settings.
-
to
-
Specify to whom mail should be delivered. Takes array or single emails.
-
subject
-
subject of email. Takes only string
-
template
(optional) -
template of email. Takes only symbol
-
options:
:blank
,:standard
(default) -
partial_file_path
(optional) -
partial file path of email. Takes only string
-
partial_locals
(optional) -
partial locals of email. Takes only hash
-
body
-
body of email. takes html string or normal string.
-
button_text
(optional) andbutton_link
(optional) -
If email template requires a link with button, use these attributes.
-
attachments
(optional) -
If email template requires attachments, use this attribute.
Examples
Here are some examples of how to use the CmAdmin.send_email
method to send emails:
CmAdmin.send_email(
to: ['anbu@commutatus.com'],
subject: "[DMSv2] New Prospect Created!",
partial_file_path: '/cm_admin/mailers/prospect_admin_notification',
partial_locals: { user: User.last }
)
-
With from email:
CmAdmin.send_email(
from: 'info@commutatus.com',
to: ['anbu@commutatus.com'],
subject: "[DMSv2] New Prospect Created!",
partial_file_path: '/cm_admin/mailers/prospect_admin_notification',
partial_locals: { user: User.last }
)
-
With Link Button:
CmAdmin.send_email(
to: ['info@commutatus.com'],
subject: "New User Created!",
partial_file_path: '/cm_admin/mailers/user_admin_notification',
partial_locals: { user: User.last },
button_text: 'View user',
button_link: 'http://domain.com/user/1'
)
-
For sending simple HTML content.
CmAdmin.send_email(
to: ['anbu@commutatus.com'],
subject: "[DMSv2] New Prospect Created!",
body: '<p>Simple HTML content to be added here.<p>'
)
Note: button_text and button_link are optional
-
Sending Email with blank template
CmAdmin.send_email(
to: ['anbu@commutatus.com'],
subject: "[DMSv2] New Prospect Created!",
template: :blank,
body: '<p>Simple HTML content to be added here.<p>'
)
-
Sending Attachments with email
CmAdmin.send_email(
to: ['anbu@commutatus.com'],
subject: "[DMSv2] New Prospect Created!",
body: '<p>Simple HTML content to be added here.<p>'
attachments: [
{
filename: 'sample.pdf', file_content: '...'
},
{
filename: 'sample.pdf', url_path: '...'
}
]
)
NOTE: attachments should be a array of hash, hash should have two keys only:
-
filename
-
file_content or url_path
NOTE: file_content should be base64 encoded string of file content/blob. We can use
-
Base64.encode64(File.open(file_path).read)
to read the file content from a file path and encode it. -
Base64.encode64(URI.open(file_url).read)
to read the file content from a url and encode it.