Tag Archives: .net core

ByAlexia Pamelov

How to Send Mail Using SendGrid In .NET Core

CheapWindowsHosting.com | Best and cheap ASP.NET hosting. Sending mail in .NET Core is not easy as .NET Core does not support SMTPClient class. In .NET Core, there is System.NET.Mail assembly where the SMTPClient is missing, that we use while sending mails in a full framework .NET Application.

So, this article explains how we can send mail in .NET Core, using SendGrid.

 
What is SendGrid?

SendGrid actually does more than sending emails. According to SendGrid, it is a “Marketing & Transactional Email” Service. SendGrid API integrates via email API to ensure the delivery of most important emails. 

Requirements
  1. Visual Studio 2015
  2. .NET Core
  3. Azure subscription to create SendGrid (I am using Azure to integrate SendGrid else you can create a trial account on SendGrid Site)
Advantages
  1. Easy to use with integrated API for .NET Core.
  2. Cloud based.
  3. Azure Integration
Before starting to code, we need to send up the SendGrid account.

Log into your Azure Account and add a new SendGrid Email Delivery Resource.

  • Click “New” to add a new resource.

cb1

  • Type “SendGrid Email Delivery” to find SendGrid.

cb2

  • Click “Create”.

cb3

  • Fill in the required settings in SendGrid as per your subscription.

cb4

  • Select the “Free Plan” from the SendGrid Pricing Tier or as per your requirement.

cb5

  • Click “Create” and “Purchase” after all the information has been provided. 
  • After the resource is created, a username, password, and SMTP Server details will be provided. Note that down.
  • We can send emails using username and password but the best way is to create an API key. So, click on “Manage” to go to SendGrid website and create an API key which we will use while sending an email. 
  • After you save, the API Key will be generated. Please note it down.
  • Now, let’s come to the coding part. Create a .NET Core Console application and add the below code.
using SendGrid;  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net.Mail;  
using System.Threading.Tasks;  
namespace SendMail {  
    public class Program {  
        public static void Main(string[] args) {  
            var message = new SendGrid.SendGridMessage();  
            message.From = new MailAddress("jj1735@gmail.com", "Julian");  
            message.Subject = "Sending Email using SendGrid";  
            message.AddTo("jj1735@gmail.com");  
            message.Html = "<p>Hello from Julian</p>";  
            var client = new Web("YOUR API KEY");  
            client.DeliverAsync(message).Wait();  
        }  
    }  
}  

 The project.json

{  
    "version": "1.0.0-*",  
    "buildOptions": {  
        "emitEntryPoint": true  
    },  
    "dependencies": {  
        "Microsoft.NETCore.App": {  
            "type": "platform",  
            "version": "1.0.1"  
        },  
        "SendGrid.NetCore": "1.0.0-rc2-00004"  
    },  
    "frameworks": {  
        "netcoreapp1.0": {  
            "imports": ["dnxcore50", "portable-net45+win8"]  
        }  
    }  
} 

 Now, run the application and check for the sent mail.

ByAlexia Pamelov

What Difference Between .NET Framework and .NET Core

CheapWindowsHosting.com | Best and cheap .Net core. hosting. What should you choose for your next application – .NET Framework or .NET Core? This was a question asked by a business owner in one of my advisory meetings, recently.

In this article, let’s compare these two platforms and see if we can come to a conclusion.
 
.NET Ecosystem

Let’s review the following .NET ecosystem architecture diagram, as of today.

DotNet-Architecture

As you can see from the above diagram, the .NET ecosystem has three major high-level components – .NET Framework, .NET Core, and Xamarin.

Xamarin is not a debate at all. When you want to build mobile (iOS, Android, and Windows Mobile) apps using C#, Xamarin is your only choice.
 
The .NET Framework supports Windows and Web applications. Today, you can use Windows Forms, WPF, and UWP to build Windows applications in .NET Framework. ASP.NET MVC is used to build Web applications in .NET Framework.
 
.NET Core is the new open-source and cross-platform framework to build applications for all operating system including Windows, Mac, and Linux. .NET Core supports UWP and ASP.NET Core only. UWP is used to build Windows 10 targets Windows and mobile applications. ASP.NET Core is used to build browser based web applications.

So, what to choose?

If you have to make a choice between .NET Framework and .NET Core today, here is the criteria. Keep in mind, a year or so down the road, you may not want to choose .NET Framework at all.

As of today:

.NET Framework is a better choice if you:

  • Do not have time to learn a new technology.
  • Need a stable environment to work in.
  • Have nearer release schedules.
  • Are already working on an existing app and extending its functionality.
  • Already have an existing team with .NET expertise and building production ready software.
  • Do not want to deal with continuous upgrades and changes.
  • Building Windows client applications using Windows Forms or WPF
.NET Core is a better choice if you:
  • Want to target your apps on Windows, Linux, and Mac operating systems.
  • Are not afraid of learning new things.
  • Are not afraid of breaking and fixing things since .NET Core is not fully matured yet.
  • A student who is just learning .NET.
  • Love open source.
The following table may help you make your decision.
 
High-performance and scalable system without UI .NET Core is much faster.
Docker containers support Both. But .NET Core is born to live in a container.
Heavily reply on command line .NET Core has a better support.
Cross-platform needs .NET Core
Using Microservices Both but .NET Core is designed to keep in mind today’s needs.
User interface centric Web applications .NET Framework is better now until .NET Core catches up.
Windows client applications using Windows Forms and WPF .NET Framework
Already have a pre-configured environment and systems .NET Framework is better.
Stable version for immediate need to build and deploy .NET Framework has a been around since 2001. .NET Core is just a baby.
Have existing experienced .NET team .NET Core has a learning curve.
Time is not a problem. Experiments are acceptable. No rush to deployment. .NET Core is the future of .NET.