Catchy title, but it explains exactly what is in this post.
Windows Runtime Component
What is WinJS?
Creating the app
Firstly create an app using the basic WinJS template in Visual Studio.
Choose the target and minimum versions.
Now a new project is needed to be added to the solution, so right click the solution.
Choose Windows Runtime Component under the C# collection.
Right click the references of your main UWP project and add this component.
To use SendGrid for messaging, the best component to use is called LightBuzz and can be found here:- https://github.com/LightBuzz/SMTP-WinRT
Although it’s easy to add references via NuGet, for some reason with UWP apps created this way, the library was not copied locally, so I cloned the repo from GitHub and built the project locally giving me a nice shiny library I can then reference old school.
Just make sure it is set to copy local in its properties.
Now for some code.
In the class code auto generated when you created the Runtime Component, make sure you have the using statement for LightBuzz.SMTP and add this code:-
When using SendGrid, you can add extra credentials to your account that helps separate out different usage scenarios. I have credentials set up for my WebUp app and I have used it here, just swap out with your credentials.
While in the Component code, have a look at the project.json file, it will list all the runtimes that are available for the component. When running this app,, you will need to change the environment to one of these as ‘Any CPU’ does not work.
Now back in the UWP code, add something like this to the app.onactivated function; obviously you will want to put it somewhere else, but for this example it will work.
Enter your email address and run the app. With any luck you should start to receive emails direct from your app via SendGrid.