The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
Sitefinity offers very easy extensibility of our default SmtpSender class. Since our Email Campaigns module uses the Sitefinity's NotificationService to send out the campaign issues, the SmtpSender gets resolved dynamically and can be replaced from the Notification profile.
This article shows how you can inherit from the default SmtpSender and add logic that in this case detects whether a message has failed delivery due to System.Net.Mail.SmtpStatusCode.MailboxBusy status code (450) and re-sends it if necessary.
If the message falls within this case the custom sender attempts to re-send it for a predefined number of retries and a predefined period between the retries. To ease configuring this logic we have exposed the numberOfRetriesPerMessage and waitBeforeRetry parameters to be read form your site's web.config <appSettings> section. In other words, here's the full implementation of the overridden SendMessage method of the custom SmtpSender:
As you can see above, we have explicitly restricted the logic for retrying the sending only to messages with status
System.Net.Mail.SmtpStatusCode.MailboxBusy. You are free to extend it as per your specific requirements.
Here is the full source of the CustomSenderSMTP class. In order to use it you need to include it in your project's solution, and build it. When done, you need to go to Administration>Settings->Advanced->Notifications>Profiles->Default and change the SenderType property to the CLR type of the custom SmtpSender class (in our case that is SitefinityWebApp.CustomSenderSMTP). From this point on Sitefinity will use the custom SmtpSender instead of the default one, and the sending logic will go through the custom SendMessage implementation.
In addition to the sample, there are cases where you need to catch exceptions related to the custom sender at runtime. This can be done by replacing the base SendMessage method in a try-catch statement, so that when an issue occurs, the error generated can be caught and dealt with appropriately by either logging it or handling it with additional logic. Here is the modification to the sample:
By default we have preset the number of times Sitefinity retries to send a message to 3, and the default period between retries is 1000ms (1 second). If you want to control these you can add the following entries in your web.config <appSettings> section:
video of the sender in action.
Changing the values will change the logic behavior accordingly. Here is a short
Additionally. our default SmtpClient.Timeout is set to 100 000 milliseconds (100 seconds). If you wish to increase this value, you can override the System.Net.Mail.SmtpClient to get a value you have set in the web.config:
This allows you to add an additional key to the appSettings node of the web.config named and smtpClientTimeout. Adding a value to it will alter the default one.
View all posts from Ivan D.Dimitrov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
You have the right to request deletion of your Personal Information at any time.
You can also ask us not to pass your Personal Information to third parties here: Do Not Sell My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.Learn More