How To Configure Smtp Details In Sitecore

Sending emails from your website is a very common requirement in most websites. Someone signs up to your newsletter, someone joins your membership scheme etc.. There are several way to send emails within Sitecore and this tutorial will guide you how to configure them.

Webforms For Marketers

WFFM is probably the most commonly used Sitecore module. WFFM allows non-technical people to create web forms. As part of the process, the end action of a completed form might be for a user to be sent an email with a link to a downloadable white paper for example. To configure WFFM, open the Sitecore content editor:

Sitecore_setting_stmp_details

To configure WFFM, navigate to ‘Sitecore’ -> ‘System’ -> ‘Modules’ -> ‘Web Forms for Marketers’ -> ‘Settings’ -> ‘Actions’ -> ‘Save Actions’ -> ‘Send Email Message’. In here in the ‘Submit’ section you should see a text area called ‘Paramaters’. It’s this section you define the SMTP details:

<Host>localhost</Host><Port>25</Port><From>[email protected]</From><IsBodyHtml>true</IsBodyHtml>

This is a very basic configuration. In most cases you will also want to define a username/password for your SMTP gateway. This can be done using the following tags:

<Login></Login><Password></Password>

You can also specify SSL using

<enableSSL>true</enableSSL>

One word of caution, although the setting is for SSL, WFFM actually uses TLS in the back-end. If you have no idea about the difference between SSL and TLS, I would recommend reading this.

To make WFFm work securely you need to set the port to 587 and not the default SSL port of 465.

After you click ‘Save’ in the top ribbon, all forms that have been configured to send email messages on submit should now start to work.

Default Smtp Settings

Next up is the default Smtp settings that is used through Sitecore. When I say default I mean emails like password recovery and workflow emails for example. If you open up your ‘web.config’ file you should be able to find a section like the one below:

<settings>
<setting name="MailServer" value="localhost" />
<!--  MAIL SERVER USER
If the SMTP server requires login, enter the user name in this setting
-->
<setting name="MailSearverUserName" value="" />
<!--  MAIL SERVER PASSWORD
If the SMTP server requires login, enter the password in this setting
-->
<setting name="MailServerPassword" value="" />
<!--  MAIL SERVER PORT
If the SMTP server requires a custom port number, enter the value in this setting.
The default value is: 25
-->
<setting name="MailServerPort" value="25" />
</settings>

Hopefully, configuring this should be pretty straightforward. Emails triggered via Sitecore should now start working for you. If you want to enable SSL for your default Sitecore emails then you can do this in the usual .NET way. In your web.config file, you can add the following configuration:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network enableSsl="true" />
</smtp>
</mailSettings>
</system.net>

To send an email manually using these settings, you can use the following code using the Sitecore.MainUtil.SendMail:

var emailMessage = new MailMessage("[email protected]", "[email protected]", "subject", "test body");
MainUtil.SendMail(emailMessage);

Conclusion

In today’s post, I’ve covered the main way you will send emails through Sitecore. Probably the most important is the WFFM as this is where the majority of the lead generation will begin. If you want to configure the ‘default’ Sitecore emails you will need to have a look in your web.config. There are a few surprises when enabling emails but by and large, it is pretty straight forward.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *