Category Archives: Programming

Sending Emails with ZOHO

Since Google Apps stopped being free of charge I needed an alternative service to hook a newly registered domain to in order to receive an authorization request when creating a new SSL certificate for the domain. Most CAs require an email address with the domain name to verify ownership. If you are just spinning up a domain without an email server this can cause issues. Zoho mail offers a free email service to suite this need, as long as you are only using it for one domain that is.

Creating a new account and setting up your domain with it is simple, Add a CNAME record to your domain with their information to verify ownership and you’re good to go!

I decided to write a simple subscription service to test out their email functionality. The only snag I ran into here was needing to enable incoming SMTP in the settings. The code required to write an email through the Zoho server is simple:

 SmtpClient client = new SmtpClient
 {
    Host = "smtp.zoho.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential("from@address.com", "password")
 };

 using (MailMessage notificationMessage = new MailMessage())
 {
    notificationMessage.From = new MailAddress("from@address.com", "Display Name");

    notificationMessage.To.Add("to@address.com");

    notificationMessage.Subject = "You've been subscribed to cat facts!";
    notificationMessage.Body = "Welcome to the club!";

    client.Send(notificationMessage);
 }

Some limitations of Zoho are sending oh behalf of another email address. Unless the email you are sending is from an address of an account on Zoho the message will not send.

 

HTTP to HTTPS automatic redirection in IIS 8

Some syntax changes in the latest IIS 8 concerning the URL Rewrite plugin caused issues when transitioning from IIS 7.5.

application_request_routing

In The site Application Request Routing plugin pane, open up “Server Proxy Settings…” on the left, then enable the server proxy:

application_request_routing_2

 

Back in the site you are configuring, create a new URL rewrite rule:

application_request_routing_3

 

The filter should match anything coming into the site, check to see if it is HTTPS, and if not redirect it. The Conditions section is where the pattern syntax had to be altered from what I had read from other sources. Previously regular expressions were used to the effect of “^0$”, a string that would not work in IIS 8. The filter should simply be “off”.

application_request_routing_4

Further down on the rule set the new URL to be the previous one except with HTTPS on the front of it. The {HTTP_POST}{R:1} help recreate the URL originally being visited before the redirection. After the rule is created trying to get to http://mattlapaglia.com redirects to https://mattlapaglia.com !