Can I replace Sitecore Email Sending Service? - email

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.

Related

Email open tracking

I have to create email tracking system, but the problem is that when the sender opens an email this is counted as an opening by the recipient.
When I send an email through Polymail (or some other tools for tracking emails), then in the 'sent' folder I have an email without a tracking pixel, but the recipients of this email have the pixel and at the same time everyone have different code inside (I think, to determine which of the recipients opened the email).
How is this possible? The sender and the recipients have different contents of the same email. Can this be implemented using smtp / imap / gmail-api?
For standard IMAP/SMTP setups (specifically: not GMail), the message is submitted twice, once to SMTP to be sent, and again to IMAP to be placed in the Sent mailbox.
There is no requirement that these be the same: in fact, in normal use, the BCC header, for example, is submitted to IMAP, but not SMTP.
GMail, and a few others, while trying to be helpful and save bandwidth, do the copy automatically, but make it impossible to supply different versions. (Unless you want to try to find the duplicates and delete them out of band).
Current Email protocols don't send any kind of ACK to the Sender when mail is opened. So you need to put some kind of analytic tool inside the mail contents to keep the track of it.
Some suggested methods and widely used tool is Bananatag.
Alternatively, you can use custom Google Analytics for the same. Refer here https://dyn.com/blog/tracking-email-opens-via-google-analytics/

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.

Email Intermediary Between Sender and Receiver

I am using SES for emailing (currently only sending but I'm open to using it for receiving as well), EC2 server for web app and RDS.
Web application written in Java.
I would like to act as intermediary for users that email each other through my website by having all emails sent between users go through me.
The purpose is to conceal the emails of the two users who are emailing each other.
I thought of doing something like this:
1) The initial email is sent on the website, there it receives a unique ID which is stored in the database (containing the email addresses of the sender and receiver).
2) All subsequent emails between the two users are sent to the website's email address with the unique ID appended as a label (eg:bob+[uniqueId]#domain.com).
3) The email is accordingly routed back and forth between receiver and sender (I perform minor modifications to the email).
(Airbnb does something similar when users of its site message each other).
An extra caveat is that I would like attachments to be able to be included in the emails as well (and thus, they would need to be forwarded).
Is this the correct way to implement this functionality?
Should I do it differently?
If this is the correct approach, any references for how to get started? Specifically, I'm not sure how to use a lambda function (if that is what I would be using) to send an email, or to query my RDS.
Thank you
This sounds similar to private email systems I've seen on other sites. I think you have the correct idea. I would recommend using SES for both sending and receiving, and use a Lambda function to process the incoming emails.
You can have SES fire a Lambda function when you receive an email: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-lambda-example-functions.html
The other option for triggering processing of incoming emails would be SES->SNS->Java application webhook. Or you could queue them up via SES->SNS->SQS and have your Java application subscribe to the SQS queue.

Tracking response to an email

I need to send via agent some emails and I want to track the responses to these emails with an agent on the mailbox of the user.
Is there any field I can use to set/read to achieve this?
The flow:
1) the user create a document in a database (on the web);
2) the WebQuerySave agent creates the email, saves it in a mail-in db and sends it to the recipient;
3) the recipent sends a reply;
4) an agent on the mail-in db should read this reply and write some data back to the original document made by the user... and that's what I'm trying to do and I can't rely on the subject because it's all on the final users hands...
Is there any way I can do it?
Thanks for any advice.
Since you are dealing with outside recipients and can't control the software that they use or how they use it, it is going to be difficult to handle 100% of cases. You are going to need to build a mechanism into your solution for marking exception cases where automatic matching fails so that someone can handle them manually.
That said, you can set a special flag in your outgoing mail. Assuming that your webQuerySave agent uses mailDoc as the object name for the NotesDocument that it is going to mail, just do this:
mailDoc.ReplaceItemValue("mySpecialFlag",evaluate("#unique"))
In order to get this value to go out in the email, you are going to have to make sure that the Domino server that performs the conversion from Notes format to SMTP is configured with the outbound MIME option to "send Notes private items", which is described here. This will create a custom x-notes-item header in the outbound message, and as long as the receiving email system preserves it and copies it into the end-user's reply message, that header will be received back by Domino and converted into an ordinary NotesItem that your agent in the mail-in database can look for. I think that most ordinary mail software will preserve this header for you in replies, but you will need to be handle cases where the haeder doesn't come back either because the outside mail system's software doesn't preserve it or because the user creates a new message and copies the old one into it instead of doing a normal reply.

ClearQuest Custom Email

I'm trying to create a custom email for ClearQuest in order to:
format the message more neatly
include a hyperlink to a change request (which is based on the Defect schema) on our local intranet
The only way I know of to send an email is to add an email rule using a static form submission via a Email_Rule Stateless Record Type (which comes with the Defect schema). The only customization it allows is to select the fields to include in the email, the criteria specifying when to send the email (e.g. when the state changes), and who to send it to.
I'm assuming a script is run (either in VB or Perl) in order to aggregate the information needed for the email and perhaps another to actually send the email. I'm looking for one or both of those scripts. Does anyone know where those scripts are located on a ClearQuest server?
I've come across various references from IBM that pertain to custom emails, but none were very helpful.
http://www.ibm.com/developerworks/rational/library/4329.html (from 2003 and ClearQuest v1.1)
http://www.ibm.com/developerworks/rational/library/3931.html (from 2002, no version specified)
We're using ClearQuest v7.1.2. Does anyone know of any good references dealing with ClearQuest custom emails?
We are using Clear Quest Email Notification Package, that allows much more flexible email notifications.
Link
The package is compatible with ClearQuest 7.1.2.
You can download new version from the following location:
http://cqadmin.org/wiki/ClearQuest_Email_Notification_Package
Newer versions of ClearQuest have a new Email notification package that does what you want and is also robust to network failures and supports different email services and a high level of security. That is, the email is saved as a record and a service runs that ensures emails get sent.
The name of the package is EmailPlus and it also uses a WebApp, EmailRelay, which performs the email notification duties.
More details found here.
https://www.ibm.com/support/knowledgecenter/SSSH5A_8.0.0/com.ibm.rational.clearquest.schema.ec.doc/topics/sch_pkgs/c_emp_package.htm