Orchard Hungary is an archive

This site is now an archive. We'll keep it so the content is accessible, but we won't update it anymore. However, we frequently publish Orchard-related news on our other site Orchard Dojo, so be sure to check that out instead. And if you're interested in news about our Orchard development company, Lombiq, check out our website.

Sending emails from Orchard: Windows SMTP & Orchard.Email

Tags: Orchard, brotip, IIS, maintenance, E-mail, SMTP

And now, the final episode of the Orchard maintenance trilogy: we will look into the installation and configuration of a Windows SMTP Server, including some steps about security, and set up IIS and the Orchard.Email module to be able to cooperate. Before that, a short roundup on the previous episodes:

  1. Setting up an Orchard site in IIS Express 7.5
    • creating an AppPool in IIS for our site
    • shut down/delete the Default Web Site
    • connecting the new Web Site with the Orchard.Web folder
  2. Visual Studio Web Deploy to IIS
    • Orchard.Web project's settings: Publish Settings saved into a profile
    • App_Offline
    • optional: settings of the Deployment Package
    • usage of the URL-Rewrite IIS module (Canonical Domain Name)

Let's get started! First, we'll install the Windows SMTP Server: in the Start-menu select "Turn Windows features on or off", and in Features, select "Add features". Check the box for SMTP Server and follow the ritual Next-Next-Next-Finish process.
It is possible, that the service for the SMTP Server won't start automatically with your system which would make your email system unavailable after a restart. To check this, you need to start "Local Services" and look for "Simple Mail Transfer Protocol": it's "Startup type" property must be set to "Automatic".

Now start Internet Information Services (IIS) 6.0 Manager and select SMTP Protocol. In the rigth-click menu of the local computer, choose New - SMTP Virtual Server. In the wizard the following need to be set:

  1. Name: a name for your mail server, eg. "CoconutMail".
  2. IP: the IP address of your server, eg. 12.34.56.78.
  3. Home directory: a folder to store unsent emails (due to an error, like invalid target), generally it's C:/inetpub/mailroot.
  4. Domain: the name of the machine.

We have a working server (start it, if hasn't started), but there are a few important settings left: right-click on the server's name and choose "Properties". In the general settings, you may want to enable logging: choose a format, a folder to save the logs into (eg. C:/inetpub/smtplogs), select the data to be saved in the logs and the size/duration limits.
In the "Access" tab, there are three sub-menus: Authentication, Connection and Relay Restrictions; we'll look into the latter two: these determine, which clients will be able to use the mail server. In our case the only entry for both is the IP address of our server. In both cases, you can choose between "Only the list below" and "All except the list below", in most cases the first option will serve you.
Finally, in the "Messages" tab you can enter an email address to send reports to for any unsent email.

In the next step, we'll set up some rules for the Windows Firewall to increase safety. Altough these settings may be unnecessary (due to the settings in Connection / Relay Restrictions), these steps may come handy later. In the Firewall settings under "Inbound Rules" select the "Block the connection" Action for "Simple Mail Transfer Protocol (SMTP-In)". Generally, an outbound rule is also unnecesarry, but may be useful under certain conditions: in "Outbound Rules" create a new rule. Enter a name (eg. "SMTP-Out"), enable the rule and allow communication. Set the protocol type to "TCP" and port definition to "Specific port" for Port 25.

Brace yourself, we're close to the finish line. In IIS 7.5 enter the settings of your site and choose "SMTP E-Mail" in the ASP.NET section: for email address, you can enter any (even fictional) address for the sender of your emails. Check the box for "Use localhost" and enter 25 for port number. These settings will appear in the web.config as the following:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="[email protected]" />
        <network defaultCredentials="false" host="localhost" port="25" />
      </smtp>
    </mailSettings>
</system.net>

And the last thing to do (also the easiest) is to set up Orchard.Email module via the admin interface. For the sender email enter the same email address you used in the IIS configuration, the server's IP address for host name, and finally, enter 25 for port number. Leave the remaining two checkboxes unchecked.

We're ready! I hope no one suffered a TLDRException during reading this. :)

1 Comment

  • jason palmer said

    Thanks for this, am starting to standardise on the Orchard CMS for startups.

    They all want a cms, newsletters, social media feed etc. and I just love c# so makes sense.