build and send chart as part of Email in java using VelocityEngine - charts

I want to create and add chart in email body using vm templates. Any suggestion about existing librariesor how to do that? Currently we are using JavaMailSender and VelocityEngine to send emails.

Related

Grafana - send an email from custom panel plugin

I created a custom panel plugin (TypeScript + React) that get data from ElasticSearch to monitor our systems. The plugin with custom logic (based on data) shows the state of the systems. Now I would like to send an email to a SMS gateway (or even to voice gateway). That just means send an email to a specific email address with phone numbers in the subject and a body with a specific format.
As far as I know Grafana can send an email via alerts that are linked with some graph panel and some threshold. I don't have any of that.
Is there a way to send (trigger via code) an email when my panel logic detects an error/warning? Do I have to write the sending logic (in the panel) myself with some nodeJS lib (without grafana) or is there some other way?
From Grafana forum:
AFAIK there’s no official plugin support for sending emails, so I’m
afraid you’d need to implement it yourself.
So I plan to user nodeJS library nodemailer to send en email from the panel plugin.

Best implementation to send emails using crons

I have a system which is already using cron to send emails. But i feel it is not a very good implementation, and i want to improve it. This is what i am doing right now:
Saving required 1 line text in database along with receiver's details, and couple of CTA's, and inside the cron i am adding that text in the main body, adding header & footer and sending it to user.
I am planning it to improve like this:
Using blade templates.
Creating different templates for different actions (eg registration, forgot password etc), right now there are no different templates.
As soon as action is triggered, prepare the html email template which is ready to be sent to user, and save it in database.
Use cron, pick the saved html template and send it to user.
I am not sure if this is the right way to do this. Is it fine to save whole html in database? or should i instead save variables in db as json and then use those variables to create the ready to be sent template in cron itself and then send it?
Or should i use some queuing methodology AWS provide to combine it with SES and submit emails to it without storing it in database.
Please suggest the best implementation. Thanks.
You can implement this in the following manner using AWS SES, Lambda & Dynamodb
Configure SES to send email with your domain
When you need to trigger an email, use a Table in DynamoDB to store the email data in JSON format.
Configure Dynamodb streams to trigger a Lambda function upon new mail record creation, which will use SES SDK to send a mail.
To construct the Email body in Lambda function, you can use a template mechanism of your choice (e.g for NodeJS you can use Underscore templating) and bind the JSON data before sending the email.
In this approach mails will be send asynchronously and also make sure you have extended the SES email quotas.

Can I replace Sitecore Email Sending Service?

By default smtp server can be configed in Sitecore web.config. However is it possible to hijack the whole email sending part to use a different method instead of a smtp server? Is there some kind of pipeline?
For example, I want to use another web service to send all emails, or I want to save all of them into a database instead of actually sending them?
Also a different question would be, does content delivery instance need to send emails by default? I would assume all out-of-box email sending are from content authoring instance right?
And from my understanding, there's only workflows in Sitecore need to send emails and it can be customized by changing the email action. (Assume no Email Campaign Modules, no Webform for Markets module and etc.)
Any insight would be great help, thanks!
--------------Update---------------------29/09/2015--------------
I have got my answers, thanks everyone.
Basically I shouldn't need to working about the smtp server on CDS instances, and all email sending can be controlled by pipelines on CAS instances.
However when I checked the source code, there's only one place "Reminder" which uses the smtp server to send emails directly. So if this function is important to you, you should consider update this function.
Yes absolutely.
At runtime when you are defining the SMTPClient you can set the properties for the server by the following code
SmtpClient client=new SmtpClient("Host");
client.Credentials=new NetworkCredential("username", "password");
MailMessage mailMessage = new MailMessage();
mailMessage.from="sender#gmail.com";
mailMessage.To.Add("recipient#gmail.com");
mailMessage.body="body";
mailMessage.subject="subject";
client.Send(mailMessage);
What you can do, instead of having the values hardcoded in the code you can retrieve the values from Sitecore Items and use those, this will allow greater control for Content Editors and even use different SMTP Server in different parts of functionality.
Item emailItem = Sitecore.Context.Database.GetItem("Id of Item");
string from = emailItem["From"];
string to = emailItem["To"];
string server = emailItem["Mail server"];
string subject = emailItem["Subject"];
string message = emailItem["Message"];
There is a SendEmail pipeline apart of Sitecore's EXM aka ECM which you can override if you take the EXM route. It has two processors FillEmail and SendEmail which you can utilise or remove and add your own processor for actually sending the message.
It is possible to save the emails to a database, or rather the content, instead of sending them. This can be achieved by custom code in Sitecore or Webforms for Marketers which has Save Actions for Sending Emails or Saving to a Database and its really simple to configure.
As you said there is no need to send emails on every occasion its more about determining what you are trying to achieve and if Sending Emails, Saving to Database etc is more relevant. The great thing about Sitecore is you can create Items programmatically and store the information there, save you worrying about creating database tables, managing ConnectionStrings, setting up EntityFramework etc.
Here is a simple blog on creating Sitecore Items Programmatically.
Sitecore Workflow sending Emails is optional and can be removed by deleting the Send Email CommandAction Item from beneath the WorkflowState Item and then publish.
The easiest way to intercept all emails is to configure Sitecore to send all emails to the locally hosted SMTP server (127.0.0.1) and then grab them from there using your custom code.
There is a lot of free SMTP servers, just make sure you test them with high volume of emails before moving to production.

Adding new contact using mailgun in rails

I am trying to build app where users can subscribe for new updates.
My mailer is configurated with mailgun. Everything works fine except when I try to add new user with this method (as in official document): http://documentation.mailgun.com/user_manual.html#mailing-lists.
Honestly I have no idea how to send email adress from form directly to add_list_member(mail) without saving it to my database.
I will be grateful for any help!
Create two fields in your form
Name
Email
On Form's submission you send the input from the user to your backend for processing.
The backend takes the form's input, makes a few check to ensure the email is correct and not mispelled.
If the above is successful your backend pushes the email address and name to a mailing list, for reference that's something which you can create with the API or from the control panel (https://www.mailgun.com/cp/lists?domain=YOURDOMAIN.COM)
Then you just email the address provided in the email list

Dynamics CRM 2011 - attach file to email before send

I have a pretty standard workflow in my Dynamics CRM 2011, which sends email when new entity is created. Now, before email is sent, I'd like to attach some attachments by plugin.
Is it possible to capture some before-send event on email activity, so I could create plugin that before email is sent, do some check on created message, attach files and send it?
Edit:
Files fetched by web service from another system, they are not attachements of other entities in CRM.
CRM will create the email and then send it, as two separate actions. So you should be able to add code to a post-create plugin on the email entity which adds the attachment. Presumably your workflow will add some flag to the email so your plugin knows which attachment to add to which email.
There are two messages on Email entity: Send and SendFromTemplate. You should be able to create PreSend or PreSendFromTemplate plugins and attach files.