Pages

30 October, 2013

.Net: Sending email with AlternateView, LinkedResources: System.Net.Mail

Recently we faced an issue in receiving mails from same (sender) domain email account but using different SMTP server. Mail body has few resources like GIF, JPEG and they are loaded with AlternateView (System.Net.Mail.MailAddress.AlternateViews) parameter with linked resources. 

Ex: sender@example.com sends mail to recevier@example.com using a different SMTP server (ex: mailserver.com) i.e. not using example.com (SMTP) domain.
Result of this scenario: Receiver did not receive any email. 

In mail body, resources can be loaded with the below options.

The mail could be blocked due to Exchange Intelligent Message Filter as in Microsoft Exchange server. Also to note that emails to other providers like GMAIL, YAHOO were successful.

When we remove all the resources in the email body, email reached the destination mail boxes but without any resources. Initially, to get the resource image, the below line was used.

LinkedResource image = new LinkedResource(imageResource) { ContentId = contentId };
view.LinkedResources.Add(image);
message.AlternateViews.Add(view);

Solution:
We did a small tweak to add proper content type for the resource which apparently resolved the issue. 

LinkedResource image = new LinkedResource(imageResource, MediaTypeNames.Image.Gif) { ContentId = contentId };
view.LinkedResources.Add(image);
message.AlternateViews.Add(view);

By this way, we are explicitly defining the content type of the resource. Of-course, we can simply disable the filter in the exchange server to receive the email but amending the resources in the mail body with proper content type has been skipped by the exchange filters. 

13 October, 2013

Smart Tools-1: Add Version and Copy Content

Recently I published a Sitecore tool (idea was old but did not get time to work on itJ) to add a version and copy the field content from the source language to the selected destination language(s).

This tool does the following tasks. 
  • It adds a new version to the selected destination language(s) version.
  • It copies the content from the source language (context item) to all selected destination language(s).
  • It has the option of including the child items as well.

Installation:

There is a package which you can download from the Sitecore marketplace. You can use Sitecore inbuilt installation wizard to install the package. The package includes an assembly, XML control and a config file.

How to use:
  • Once installed, you will have a menu item in the content tree. 


  • On selecting this menu, a window will open with all the available options. Source language is from the context language. If the source language is different from the default language, please change it and select the menu. 


  • An alert window will show you the message on the completion of the process. 


That's it

Smart Tools-2 will be published soon. ;)

Update: (1/13/2015)

  • Version 2.0 has been released in Marketplace. 
  • It supports Sitecore 7.0+ and SXP 8.
  • In SXP 8 , you  may need to disable the analytics and install the package.

Update: (7/27/2016)


  • Version 3.0 has been released in Marketplace. You can download it here
  • It supports Sitecore 8.1 with shared layout. 


08 October, 2013

Tools: Recycle .NET Application Pool Remotely

Recently I created an application to recycle the .net Application pool without logging into the server. It is a .net website with a dropdown showing the list of servers. On selecting a server, user can populate the all the application pools available in that server and user can recycle the application pool.


Page with dropdown and buttons.


List of application pools and a button to recycle it. 



  • The server list can be added in the configuration file.
  • Status Check will provide you the status of the application pool.
  • This .Net application should run with an account which has admin access to all the servers.
  • SMTP can be configured in the web.config.
  • After each recycle, this application will send a mail to the list of configured email ids.
  • This application logs the activity in the logs folder.


You can download the application here.


06 October, 2013

Sitecore: Image Resizer Pipeline (ResizeProcessor) Pipeline

Sitecore has a feature in processing high resolution images while rendering in the website.

Let’s say, content authors wants to use an image as Icon, Thumbnail and full scale in the website. Normally, they will upload three images in icon sized, thumbnail sized and full scale images. They will have different name to differentiate the sizes. They can use (<img src="/url/image.png" height="100" width="100") image tag with height and width but it will render with high resolution image size even for thumbnail. But Sitecore has an option of resizing the image at runtime. 

There is a pipeline in the <getMediaStream>.

<processor type="Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel" />

This pipeline has the following advantages.
  • Depending upon the width and the height in the media url, this will resize the image and render it.  /~/media/image.JPG?h=300&w=400
  • While resizing the image, it will reduce the size of the image as well.
  • Authors can use same name for Icon, Thumbnail and Full Scale. 

Example:

High Resolution Image Size: 4.70 MB (4,938,293 bytes)

Without processor (Size – 4.7 MB): http://sitecore1/~/media/flower.JPG?h=300&w=400


With processor (Size – 55 KB): http://sitecore1/~/media/flower.JPG?h=300&w=400


Of course, there will be a performance impact for resizing at runtime. To avoid the impact, the site can be configured for ARRCache which will reduce the load on the subsequent request.


04 October, 2013

Sitecore: Ideal way to execute a long running job

One of our requirement was to execute a long running job in Sitecore Content Tree. In many cases, we end up in Timed out error. Obviously we can increase request timed out configuration. But Sitecore has a very good way of executing such long running task in a ProgressBox.

ProgressBox.Execute(JobName, JobTitle, ProgressBoxMethod, Params);

//Sitecore.Shell.Applications.Dialogs.ProgressBoxes
ProgressBox.Execute("Job Name", "Job Title ", new ProgressBoxMethod(ExecuteOperation), item);

This line of code will start progress box and the functionality will be executed in the
ProgressBoxMethod.

        protected void ExecuteOperation(params object[] parameters)
        {
            //Do the operations
           
            //Logging for the job
            Sitecore.Context.Job.Status.Messages.Add("Logs for the job: JobName");
           
            //Is the job done?
            if (Sitecore.Context.Job.IsDone)
            {
                //On completing the job
            }           
        }

By using the progress box, the long running tasks are executed successfully without getting any timed out errors. This has other methods to handle the queuing asynchronously.




blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }