How to Schedule Email to be Sent on Future Date in nopCommerce Store?

Well, In The nopCommerce store provides by default email functionality through which we are able to send email from the system in the real time scenario. But if suppose, we wanted to be sent email in future timing or on a specific date and time.
And Is it possible to send email again to the customer?
Now, not need to be more confuse. Let’s discuss the topic how to schedule email sending later. And in this blog, I will explain you with the coding for that solution in nopCommerce store.
Client’s Requirement:
My client wants to send two consecutive mail in between some time interval to the customer at the same time when they buy the product. After 7 days, the First email will be sent. And after 30 days,  another email will be sent to collect the feedback from the customer.
Solutions for sending a consecutive email to the customer in some time interval from the nopCommerce.
This is possible by updating in two methods in Nop.Service
First service is  WorkflowMessageService.cs and second one is QueuedMessagesSendTask.cs.  Now, I am going to talk about the first service. It is as bellow.
  • WorkflowMessageService.cs
Find method “SendNotification” and find below code

var email = new QueuedEmail


		Priority = QueuedEmailPriority.High,

		From = emailAccount.Email,

		FromName = emailAccount.DisplayName,

		To = toEmailAddress,

		ToName = toName,

		ReplyTo = replyToEmailAddress,

		ReplyToName = replyToName,

		CC = string.Empty,

		Bcc = bcc,

		Subject = subjectReplaced,

		Body = bodyReplaced,

		AttachmentFilePath = attachmentFilePath,

		AttachmentFileName = attachmentFileName,

		AttachedDownloadId = messageTemplate.AttachedDownloadId,

		CreatedOnUtc = DateTime.UtcNow,

		EmailAccountId = emailAccount.Id

Here you will find line “CreatedOnUtc = DateTime.UtcNow“. In this code,  you have to just change DateTime.UtcNow to the future date and time as per your requirements for the sending emails.
Second service is “QueuedMessagesSendTask.cs“. Here I am briefing about this service as follows.
  • QueuedMessagesSendTask.cs
Find method “Execute”. This method has in line code as below.
var queuedEmails = _queuedEmailService.SearchEmails(null, null, null, null, true, maxTries, false, 0, 500);

Change this method to

var queuedEmails = _queuedEmailService.SearchEmails(null, null, null, DateTime.UtcNow, true, maxTries, false, 0, 500);
By passing date time in the date/time parameter to get records which are less than the created  date and it’s pending.
Note : This solution is applicable to nopcommerce version upto 3.7
NopCommerce 3.8 has already inbuilt functionality for this
I hope, this blog will resolve and help to send and schedule emails for your nopCommerce store. and if still it’s having any problem then you may hire a nopCommerce developer from Satva Solutions.
By | 2017-07-03T16:11:36+00:00 February 10th, 2017|How To, nopCommerce|