Best implementation to send emails using crons - email

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.

Related

What is the best/easiest way to process received email message body and resend it?

I am receiving chart data in JSON format to my email address and my goal is to convert it to chart/chart img and resend it to my email address.
I have been looking for several methods:
Google App script used for gmail. I failed to find trigger on newly received message.
Email client, that supports adding actions based on scripts to new incoming message trigger. Only one I know about is MS Outlook with VBA scripts, but creating chart image with lack of libraries available in VBA is not very elegant solution.
Open source email client with possibility to alter the code and so directly process data and resend message. The more robust email client, the harder is to change the code to do relatively simple job, I believe.
I really donĀ“t know what kind of solution this simple problem needs.
Thank you in advance.
Sounds like you are interested in some kind of gateway on the server side, not client-side. Take a closer look at your server-side implementation. For example, you may start from the Mail flow rules (transport rules) in Exchange Online page.

Retrieve Mail-Attachments in LogicApp for Azure Function call

I have a use case in which I have a Logic App which triggers as soon a Mail is sent to a particular email address.
This email contains multiple attachments. The Logic App then needs to call an Azure Function and pass the Body of the mail and the attachements to the Azure Function.
Actually I am struggling with getting the email attachements in a way (Array?) which allows me to pass them to the Azure Function for further processing.
Does anybody have some advice for me? I'm not very familiar with Logic Apps, so any help is highly appreciated.
You can directly use HTTP requests to send attachment, The metadata used in the example can be obtained directly in Add dynamic content.
You can refer to Post Multipart/Form-data using Azure Logic Apps.
==================update===========================

Amazon WorkMail: Can AWS SES and Lambda be used to manipulate a received email?

I run a WorkMail client which is used to view emails received by SES. I want to set up a lambda trigger than when it detects an email from an external client, I want certain text to be censored or add an [EXTERNAL] tag to the email before the user can view the email in WorkMail. So far, the only possible manipulation I've been able to do to the email is add headers which as far as I'm unaware, will be invisible to any user viewing the email in any client until they inspect source.
I'm essentially asking if this is even possible really, as it is something I've been tasked to do from my superiors. The only method otherwise of editing the emails I can see is downloading the email, then resending it after editing with a reply-to being the original sender.

I'm using Amazon S3 and want to create a form that sends out an email when submitted. How can i do this?

So the form i previously created didn't work because my site is hosted in Amazon S3. I just want a simple form that sends an email when the user clicks submit.
ron.capptivation.com/cappdev2
form is at the bottom
Any ideas on how to make this form work and send an email?
You'll need a back-end service to help you send the email.
You can use a Lambda function to send the email, then setup an API gateway to funnel your requests to the Lambda function.
Then in your static website, use Javascript to issue Ajax calls to the API gateway when the form is submitting.
A static site on S3 can't process form submissions so you can't do this with just S3. You could either create your own server process to handle form submissions, possibly on EC2 or Lambda, or you could use a service like Wufoo forms.
The other respondents are correct in that you'll need a back-end service. One popular option is formspree. Another alternative would be posting a form's contents to something like Slack or HipChat using webhooks, such as explained in this blog post.

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.