Tag: email

Using Azure Functions to receive daily Website Updates via Email

Note: In this blog post, I’m talking about Azure Functions, which are currently in preview. Settings, functionality, pricing, etc. may still change.


I’m constantly trying to optimise my life by automating small tasks, so that I can either save some time and get things done without having to remember them. For example, I’m a big fan of both IFTTT and Instapaper, and use these two in combination to have new blog articles (e.g. from dev.office.com/blogs) posted into my Instapaper account automatically, so I can’t read those easily and quickly when I’m travelling to and from work. I do not need to check on a daily basis for new articles, and I can start reading new ones the moment I’m on public transport.

Recently, I started looking at Azure Functions. If you’ve never heard of them before, I recommend starting with the official Azure Functions Overview for an introduction, followed by Scott Hanselman’s and Troy Hunt’s recent blog post on potential use cases. After playing around for a short while with them, I thought I’d give them a chance for a mini-project: I’ve been following Packt Publishing’s Free Learning eBook offer for a while now. When I say follow, I actually mean I open my browser, open the page, and check which new eBook is available.

Pack Publishing Free Learning eBook Offer

This obviously takes some time, and additionally I forget to do it on a daily basis. While I do not get every free daily eBook, I still want to know if there’s something interested published. So, what I was looking at doing was to implement a small website monitor that checks the offer page once per day and sends me an email with the offer details. Quite simple, should be up and running within a short time.



First of all, you obviously need an Azure account. In addition to that, you need a SendGrid account to send out emails. Luckily, Azure subscribers can get a free SendGrid account with up to 25,000 emails each month. More than enough for personal use! Within Azure, click on New, type in SendGrid, and follow the steps to add it:

Azure SendGrid

Once done, create a new API Key in SendGrid and keep it somewhere (as we will need it later).

Furthermore, you also need to add a Function app in Azure if you haven’t already done so. When you create a Function app, you need to specify whether to use a Dynamic App Service Plan or a Classic one. For our small exercise, Dynamic is the best choice (“You don’t have to worry about resource management, and you only pay for the time that your code runs.“). Read more about the differences on How to scale Azure Functions.

Note: You can review the pricing for Functions here (note: Functions are still in Preview, pricing may change). You can also estimate your total cost by using the Azure Pricing calculator. Here’s my estimate for the Function I’m talking about:


Yes, you can safely run your Function for quite a couple of times before getting charged for it.


Once both the Function App and the SendGrid API Key are available, you need to add the key to the Function App’s settings. Open your Function App, go to Function app settings, and select Configure app settings.


Under App settings, add a new setting with AzureWebJobsSendGridApiKey as key and your SendGrid API Key as value.


Once that’s done, save your changes. Your Function apps are now capable of sending out emails via SendGrid.

Creating the Function

In your Function App, create a new Function. Microsoft provides several templates, we’ll use the simplest one and do all the plumbing from scratch (but feel free to check out the available templates to learn how you can integrate for examples Azure Queues or Azure Blob Storage), so select the “Empty – C#” template and give it a name.

Once created, each Function offers you 4 pages where you can manage it – Develop, Integrate, Manage, and Monitor.


Let’s start with setting up the basic “structure” of our Function on the Integrate page. Initially, as we’ve chosen the Empty template, there are no Triggers, Inputs, or Outputs defined. What we want to set up is a Timer trigger (to run our code on a daily basis) and a SendGrid Output (to inform us about the latest offer):


First, add a new Trigger and select the Timer trigger template. Set the Schedule to 0 0 0 * * *. which means that the Function runs every day at midnight (once you add a Timer trigger, the page will also provide some documentation on the format for this in case you want to define your own schedules). Remember to click Save.


Next, add a SendGrid Output. You have the possibility to configure a couple of required parameters either on the configuration page or in your code. Leave the Message parameter name as it is (this is the variable we’ll use in our code), and define the other values as required. As I’m sending the email to myself, I added my email address to both the To and From fields. The Subject and Body will get defined in the code.


Save again, and click on Develop. At the top of the page you’ll see the Code section where you can define the underlying code of your Function.


Copy the following code sample and replace any existing code in your Function:

#r "SendGridMail"

using System;
using SendGrid;

 static string packtUrl = "https://www.packtpub.com/packt/offers/free-learning/";

 public static void Run(TimerInfo myTimer,  out SendGridMessage message, TraceWriter log)
     message = null;    
        using (var httpClient = new HttpClient())
             string pageContent = httpClient.GetStringAsync(packtUrl).Result;
             //the content we're looking for comes after a div tag with the class dotd-title
             int tmpIndex = pageContent.IndexOf("dotd-title");
             string offerDetails = pageContent.Substring(tmpIndex +15, 3000);
             //we've now got more content than required, removing anything that is not part of the article description
             offerDetails = offerDetails.Substring(1, offerDetails.IndexOf("dotd-main-book-form")-20);
             offerDetails += String.Format("<br/><br/><a href='{0}'>PacktPub Free Learning</a>",packtUrl);
             //parsing the book title here
             string bookTitle = offerDetails.Substring(offerDetails.IndexOf("<h2>")+4,
             message = new SendGridMessage()
                 Subject = String.Format("Packt's Free Learning Offer: {0}",bookTitle),
                 Html = offerDetails

             log.Info("Finished successfully");
     catch (Exception exc)
         log.Info("Exception:" + exc.Message + exc.StackTrace);

Note the following:

  1. The first line (starting with #r) is used to add a reference to an external assembly (documentation)
  2. public static void Run is the main function which gets called when your Function runs. As you can see, we have 3 arguments for it here. TimerInfo myTimer needs to be added as we’re using a Timer trigger. out SendGridMessage message is the SendGrid email output which we defined in the Integration configuration. We need to instantiate it and set any required properties if we want to send an email. Lastly, TraceWriter log provides a mechanism to log any information that you want during your code execution – errors, warnings, general stuff. Anything written to this log gets displayed in the Log section just below your Code section.
  3. As for the code fetching and extracting the information I want to receive via email, this is pretty straightforward. The few lines I have here instantiate a new HttpClient object, read the offer page content, and fetch the title and description (not in the nicest of ways, but hey, it’s working!).
  4. Lastly, we’re creating our SendGrid email message and assign it the appropriate subject and email body.

Here’s the final result once the code was executed (either when and the email was sent:



That’s it! A couple of minutes of configuration and coding, and I now receive daily email alerts about the latest free eBook.

Simplified POP, IMAP, and SMTP settings for Office 365

Good news, everyone! While previously we had to use a fairly long URL name for IMAP, POP, and SMTP settings on clients, Microsoft has now provided a standardized set of URLS for Office 365. In most cases, the client (e.g. Outlook) provided auto discover of the URL, however In some cases it still had to be entered manually. Instead of having to look up the correct URL for a given tenant, one can now use the standard URLs.

Here’s the official announcement:

Simplified POP, IMAP and SMTP Namespaces

It’s now much simpler to set up a POP or IMAP connection to an Office 365 account. If a phone, tablet, or desktop email program can’t take advantage of Exchange Online’s auto discover capabilities, the new Exchange Online now provides the ability to connect using unified server namespaces. Instead of being asked to locate unique POP/IMAP/SMTP server settings through Outlook Web App (which looked like “podxxxxx.outlook.com”), the following standard server names can now be used:

o POP & IMAP: outlook.office365.com
o SMTP: smtp.office365.com

Additional information
For specific steps for connecting your phone or tablet to your Office 365 email, see Phone and Tablet setup reference. For specific steps for connecting your desktop email program to your Office 365 email, see Email program setup reference.

Office 365 Service Updates (Note: this applies to all plans with an Exchange Online service, I’m linking to E/M/EDU here)

Getting more out of Outlook and Office 365 / SharePoint Online with OnePlaceMail

Does at least one of the f0llowing sound familiar to you?

  • You received an email in Outlook and want to save either the email itself or its attachments to SharePoint Online (Office 365)?
  • You have some files in your Office 365 Team Site (or anywhere else in SharePoint Online) and want to email them to somebody else?
  • Or you want to send links to some files on SharePoint Online to somebody?

A free tool (the Express version is free, an Enterprise version is available as well) to help you with all this is OnePlaceMail from Australian company Scinaptic


I’ve been using it actively for a few months to store important emails quickly in SharePoint Online, and occasionally also to send out files. The free version comes with some smaller popups, but hey, it’s free!

If you want to learn more about this product, have a look at either Joel Oleson’s blog where he does a review, or visit Cameron Dwyer (from Scinaptic)’s blog for even more information.

Note: Some other alternatives are harmon.ie and Colligo Contributor, both which I haven’t looked at in more detail.

Changing an administrator’s default email address in Office 365

After your registered for Office 365, you need to choose a prefix for your “initial domain”. This prefix will be added to .onmicrosoft.com, giving you a username for your administrator with the format of myusername@prefix.onmicrosoft.com. Afterwards, you may want to change this logon to something else after you added your own domain, such as user@domain.com. But wait! When you want to change it, you realise that it’s impossible, and the dropdown box with the domains is deactivated:


Changing your own account’s login cannot be done!


The solution? Use a second admin account!

Sidenote: You don’t need to use a license for the second admin account, which can be just a temporary account.

Create a new user (e.g. called tempadmin), and assign him Admin rights while creating him. Once you log in as this other administrator and view the first admin’s profile, you can see that the previously grayed out user name selection can now be edited:


Make your change, save it, done!

The first administrator can then add the previously used email address as an alternative email address (e.g., if you used abc@xyz.onmicrosoft.com before, and abc@xyz.com afterwards, you can add the first email address to the account so that emails sent to either will be received).


Once you’re done, you should either delete the temp admin, or at least remove his admin privileges.