How to replace/update code for System.Net.Mail SmtpClient Class with Mailkit

How to replace/update code for System.Net.Mail SmtpClient Class with Mailkit SmtpClient Class

As most of us have seen this warning.

SmtpClient Class





System.dll, netstandard.dll, System.Net.Mail.dll


This API is now obsolete.

Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is now obsolete.

Microsoft reference Link

MimeKit and MailKit are popular fully-featured email frameworks for .NET.

So how to convert you code from Old format to new.

Adding MailKit to your project via NuGet

· In Visual Studio‘s Package Manager Console, enter the following command:

· Install-Package MailKit

If you are writing a new code its good to use samples provided on Mailkit site.

Mailkit code

var message = new MimeMessage ();

message.From.Add (new MailboxAddress (“Joey”, “”));

message.To.Add (new MailboxAddress (“”, “”));

message.To.Add (new MailboxAddress (“Alice”, “”));

message.Subject = “How you doin?”;

message.Body = new TextPart (“html”) {

Text = @”Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on

Saturday and I was hoping you could make it.

Will you be my +1?

— Joey


public static void SendMessages (IList<MimeMessage> messages)


using (var client = new SmtpClient ()) {

client.Connect (, 465, SecureSocketOptions.SslOnConnect);

client.Authenticate (“username”, “password”);

foreach (var message in messages) {

client.Send (message);


client.Disconnect (true);



If you have old code then follow these easy conversions.

Now check your old code

If you have Recipientlist value=“,

Then MailboxAddress will not parse it.

It should be converted to this format.



You will note that the MimeMessage body is no more of String type (TextPart).

Sample code for conversion.

using System.Net.Mail;

private void sendemailclick()




MailMessage mail = new MailMessage();

SmtpClient SmtpServerclient = new SmtpClient(;

mail.From = new MailAddress(“”);


mail.Subject = “Test Mail – 1”;

mail.IsBodyHtml = true;

string htmlBody;

htmlBody = “Write some HTML code here”;

mail.Body = htmlBody;

SmtpServerclient.Port = 587;

SmtpServerclient.Credentials = new System.Net.NetworkCredential(“username”, “password”);

SmtpServerclient.EnableSsl = true;



catch (Exception ex)





This is the method which comes handy

Importing from System.Net.Mail

To make things even simpler still, MimeKit allows you to explicitly cast a MailMessage to a MimeMessage

Since Smtpclient is  obsolete but not the mail message, We
can still leverage
MailMessage. It had very great
parse method for email address separated with comma and mail body as string.

using MailKit.Net.Smtp;

using MimeKit;

using System.Text;

using oldsmtp=System.Net.Mail

using MailKit.Security;

private void sendemailclick()




oldsmtp.MailMessage mail = new oldsmtp.MailMessage();

SmtpClient SmtpServerclient = new SmtpClient();

//this is needed if certificate is bad or self signed.

SmtpServerclient.ServerCertificateValidationCallback = (s, c, h, e) => true;

SmtpServerclient.Connect(, 465, SecureSocketOptions.SslOnConnect);

SmtpServerclient.Authenticate(“username”, “password”);

mail.From = new oldsmtp.MailAddress(“”);


mail.Subject = “Test Mail – 1”;

mail.IsBodyHtml = true;

string htmlBody;

htmlBody = “Write some HTML code here”;

SmtpServerclient .Send(MimeMessage.CreateFromMailMessage(mail));


catch (Exception ex)






Phone: +1 646 706 1282
About me

Serene has a passion for helping clients find the perfect fit for home, work, family life, and in making a sound financial investment.Serene joins Trig Realty Co with over 18 years of technology industries experience. Her background as a lecturer, programmer and SAP software consultant allows her to use her skills to research and find the perfect home for her clients. Serene is a volunteer with the Coalition for Queens Tech Meetup, which meets regularly in LIC to showcase startup companies and promote the neighborhood’s emerging tech industry.

Serene is fluent in Mandarin, Cantonese, Malay and English. 我是蔡仪明, Trig Realty Co 地产公司的地产经纪. 我们有高效率的房源系统;可以在最短时间内找到适合你的地区和房子. 现在是你投资纽约房地产的好机会. 无论是自住、出租或投资,请马上联络我,我能满足您的需求.
WeChat ID: Serene-Chuah

Tricia Skoler

Phone: +1 347-266-0923

About me

Tricia Striano is a professional who will apply her expertise to help you find or sell your home. Persistent and persuasive, with a deep understanding of brain development, psychology and design, Tricia is a Certified Negotiation Expert (CNE) who knows that finding the right environment is one of the most important elements of happiness and success. Tricia resided in Europe for seven years and understands the challenges of purchasing a New York City home from abroad.

A resident of Tudor City, Tricia obtained her BA from the College of the Holy Cross and her PhD in Cognition and Development from Emory University. Tricia’s award winning research skills will be an asset to you as you purchase or sell your next home. Tricia enjoys soccer, swimming, biking, silkscreen printing, music, theater and design.

Mr Jin Thakur

My Bio
Jin Thakur, a member of the Keller Williams Real Estate team,
brings boundless enthusiasm, energy and passion to his role. He understands the market,
the economics of buying and selling,
and how to leverage all the tools available to get the best results for his clients.

As a former Programmer in the IT industry,
Jin Thakur understands all aspects of the real estate process and is an incredible resource for his clients. Jin Thakur owns and manages several multi-family homes and commercial real estate and with that success and knowledge, he serves as a trusted advisor to clients who are thinking about purchasing investment properties of their own.

Jin Thakur is a licensed real estate agent in the Queens LI
and the National Association of Realtors.
Jin Thakur was born in India and is a graduate of the University of Houston, Texas.
Jin Thakur also graduated from Himachal Pradesh University India in Masters of Computer Science .

“I want to bring my own experience and understanding to my clients and help them realize their goal of buying or selling their home or investment property. It is

Ubuntu with Windows 10 dual Boot

Ubuntu with Windows 10 dual Boot

Lets do Some Real work

STEP 1:Download Ubuntu

Download Ubuntu from
Once you have downloaded the ISO of Ubuntu 16.04 or 14.04, go to this page and download the latest version of Universal USB Installer.

STEP 2:Download Universal USB Installer


Plugin the USB drive in the computer and run Universal USB Installer. You need to do the following things now:

Select Ubuntu under step 1
Browse to the location of downloaded Ubuntu ISO in Step 2 section
In Step 3, select the USB drive and also check the option to format it make sure its FAT32

Step 4: Backup your Windows 10 operating system (optional but highly recommended)

Step 5: Create two partition by shrinking your drive for linux ( 1 for ex2 and 2nd for Swap )

Step 6:We will be using those partition as we boot with usb and see ubuntu install screen

Step 7:Now Restart windows and press F12 ,F2 to go to Boot up screen or Bios setting

Step 8:Stay with UEFI setting as thats the safest way to install another OS and Linux are UEFI safe

Step 9 :If you are using some version of Unix which is not UEFi compatible switch off the SAFE boot menu

Now let live USB run

Step 10:if you receive this error When I try to boot from the USB I get the error msg:

Could not find kernel CONFILE

  • Try to recreate the USb and make sure its in FAt 32 mode

Step 11: Now you see the Ubuntu screeen Ubuntu will recognize the windows system and give you option on any non Winodws OS disk In UEFI Mode

Choose the “Install Ubuntu alongside Windows Boot Manager” option.

Something else Option is not good for Dual Boot it will hide one of OS .




Step 12:You can go to advance and see any other Partition Pick those two partition createat step 5




Let it finish make sure you have selected

Choose the “Install Ubuntu alongside Windows Boot Manager” option. otherwise you may not be able to boot into dual mode and

Linux will be only OS recognized by computer .







If you want to do manual partitions like i do

Please visit

Another topic for those who doesnot want to Install ubuntu and use Windows 10 feature

The Windows 10 feature Windows Subsystem for Linux:
This can give you ability to run Linux bash command but thats not what you want.

For those who want to stick with Windows Subsystem for Linux
You do this by going “System Settings > Advanced Windows Update options” and selecting your Insider Preview update setting to the far right. This sets your Windows 10 update to the the Fast Ring.

After this check for updates, apply all of them, and restart your PC. This gives you its beta operating system so don’t do this on your production machine. Microsoft makes many updates to its Fast Ring releases and adding WSL, Ubuntu, and Bash are only part of them.

Then, you must turn on Developer Mode via Settings > Update & security >
For developers. Next, search for “Windows Features” and choose “Turn Windows features on or off” and
enable Windows Subsystem for Linux

color combination and create new color from two given color in .net

Lets discuss color capabilities in .net

Github link

For most people Color is RGB or ARGB

Color is a struct. This type provides a standard way to specify and mutate colors in the C# language. By adding a reference to the System.Drawing assembly, you can access this type and avoid writing your own color routines.

Colors can be represented as ARGB values, which store the alpha transparency, as well as the red, green and blue values. These values are stored as bytes which gives them a range of 0 to 255 inclusive.

So in order to make new color ( thats what this code does) suppose you have two colors color a and color b

Step 1

Please take the color a and  convert into RGB component via  Private Class colorcomponent

Step 2

do the same step with color b

now for individual R  take the average or fraction s if you are creating more than 2 color

Step 3

suppose R component is 100 for color a

suppose R component is 150 for color b

Step 4

then the middle color should have R value as 125

you may create 4 intermediate color in  that case  your will have R  as 110 120 130 140

Step 5 do same for G a nd B also and combine them to color back see colorcomponent class



please download zip code file code

<p> How to use this class “colorcomponent” </p>
Dim colora As Color
colora = Color.Red
Dim colorb As Color
colorb = Color.Blue
Dim coloracomponent As New colorcomponent()
Dim colorbcomponent As New colorcomponent()
Dim numberofcolor = 4
Dim outColor(numberofcolor + 1) As Color
ReDim outColor(numberofcolorinbetween + 1)
outColor = coloracomponent.getcolorarray(coloracomponent, colorbcomponent, numberofcolorinbetween + 1) code for desktop application

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim colora As Color
colora = ColorTranslator.FromHtml(“#ff66ff”)
Dim colorb As Color
colorb = Color.Green

End Sub
Private Class colorcomponent
Dim r As Integer
Dim g As Integer
Dim b As Integer
Dim a As Integer

Public Sub setcolor(C As Color)
Me.r = C.R
Me.g = C.G
Me.b = C.B
End Sub

Public Function getcolor(colorcomponent1 As colorcomponent) As Color
getcolor = Color.FromArgb(colorcomponent1.r Mod 256, colorcomponent1.g Mod 256, colorcomponent1.b Mod 256)

End Function
Public Function getcolorwithalpha(colorcomponent1 As colorcomponent, alpha As Byte) As Color
getcolorwithalpha = Color.FromArgb(alpha, CByte(colorcomponent1.r Mod 256), CByte(colorcomponent1.g Mod 256), CByte(colorcomponent1.b Mod 256))

End Function

Public Function getcolorarray(colorcomponent1 As colorcomponent, colorcomponent2 As colorcomponent, numberofcolorsneededinbetween As Double) As Color()

Dim outcolorcomponent As New colorcomponent()
Dim outColor(numberofcolorsneededinbetween) As Color
outColor(0) = getcolor(colorcomponent1)
If numberofcolorsneededinbetween > 0 Then
For i As Double = 1 To numberofcolorsneededinbetween – 1
If (colorcomponent1.r – colorcomponent2.r <> 0) Then
outcolorcomponent.r = (colorcomponent1.r) + (((-colorcomponent1.r + colorcomponent2.r) * i / (numberofcolorsneededinbetween)))
outcolorcomponent.r = (colorcomponent1.r)
End If
If (colorcomponent1.g – colorcomponent2.g <> 0) Then
outcolorcomponent.g = (colorcomponent1.g) + (((-colorcomponent1.g + colorcomponent2.g) * i / (numberofcolorsneededinbetween)))
outcolorcomponent.g = (colorcomponent1.g)
End If
If (colorcomponent1.b – colorcomponent2.b <> 0) Then
outcolorcomponent.b = (colorcomponent1.b) + (((-colorcomponent1.b + colorcomponent2.b) * i / (numberofcolorsneededinbetween)))
outcolorcomponent.b = (colorcomponent1.b)
End If
outColor(i) = getcolor(outcolorcomponent)
End If
outColor(numberofcolorsneededinbetween) = getcolor(colorcomponent2)

Return outColor
End Function
End Class

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim colora As Color
colora = ColorTranslator.FromHtml(“#ff66ff”)
Dim colorb As Color
colorb = Color.Green
Dim coloracomponent As New colorcomponent()
Dim colorbcomponent As New colorcomponent()
Dim numberofcolors = 4
Dim outColor(numberofcolors + 1) As Color
outColor = coloracomponent.getcolorarray(coloracomponent, colorbcomponent, numberofcolors + 1)
Dim i = 1
For Each genfcolor As Color In outColor
Dim t As New TextBox()

Dim j = 100
‘ t.Location = New Point(t.Location.X + i, t.Location.Y + i)
t.ForeColor = genfcolor
t.Text = ColorTranslator.ToHtml(genfcolor)
‘ t.Location = New Point(ListBox1.Location.X + 100, ListBox1.Location.Y + i)
t.Location = New Point(8 * 50, 4 + i * 30)
i += 2

End Sub

End Class

c# code
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class Form1
private void Form1_Load(object sender, EventArgs e)
Color colora = default(Color);
colora = ColorTranslator.FromHtml(“#ff66ff”);
Color colorb = default(Color);
colorb = Color.Green;

private class colorcomponent
int r;
int g;
int b;

int a;
public void setcolor(Color C)
this.r = C.R;
this.g = C.G;
this.b = C.B;

public Color getcolor(colorcomponent colorcomponent1)
return Color.FromArgb(colorcomponent1.r % 256, colorcomponent1.g % 256, colorcomponent1.b % 256);

public Color getcolorwithalpha(colorcomponent colorcomponent1, byte alpha)
return Color.FromArgb(alpha, Convert.ToByte(colorcomponent1.r % 256), Convert.ToByte(colorcomponent1.g % 256), Convert.ToByte(colorcomponent1.b % 256));


public Color[] getcolorarray(colorcomponent colorcomponent1, colorcomponent colorcomponent2, double numberofcolorsneededinbetween)

colorcomponent outcolorcomponent = new colorcomponent();
Color[] outColor = new Color[numberofcolorsneededinbetween + 1];
outColor(0) = getcolor(colorcomponent1);
if (numberofcolorsneededinbetween > 0) {
for (double i = 1; i <= numberofcolorsneededinbetween – 1; i++) {
if ((colorcomponent1.r – colorcomponent2.r != 0)) {
outcolorcomponent.r = (colorcomponent1.r) + (((-colorcomponent1.r + colorcomponent2.r) * i / (numberofcolorsneededinbetween)));
} else {
outcolorcomponent.r = (colorcomponent1.r);
if ((colorcomponent1.g – colorcomponent2.g != 0)) {
outcolorcomponent.g = (colorcomponent1.g) + (((-colorcomponent1.g + colorcomponent2.g) * i / (numberofcolorsneededinbetween)));
} else {
outcolorcomponent.g = (colorcomponent1.g);
if ((colorcomponent1.b – colorcomponent2.b != 0)) {
outcolorcomponent.b = (colorcomponent1.b) + (((-colorcomponent1.b + colorcomponent2.b) * i / (numberofcolorsneededinbetween)));
} else {
outcolorcomponent.b = (colorcomponent1.b);
outColor(i) = getcolor(outcolorcomponent);
outColor(numberofcolorsneededinbetween) = getcolor(colorcomponent2);

return outColor;

private void Button1_Click(object sender, EventArgs e)
Color colora = default(Color);
colora = ColorTranslator.FromHtml(“#ff66ff”);
Color colorb = default(Color);
colorb = Color.Green;
colorcomponent coloracomponent = new colorcomponent();
colorcomponent colorbcomponent = new colorcomponent();
dynamic numberofcolors = 4;
Color[] outColor = new Color[numberofcolors + 2];
outColor = coloracomponent.getcolorarray(coloracomponent, colorbcomponent, numberofcolors + 1);
dynamic i = 1;
foreach (Color genfcolor in outColor) {
TextBox t = new TextBox();

dynamic j = 100;
// t.Location = New Point(t.Location.X + i, t.Location.Y + i)
t.ForeColor = genfcolor;
t.Text = ColorTranslator.ToHtml(genfcolor);
// t.Location = New Point(ListBox1.Location.X + 100, ListBox1.Location.Y + i)
t.Location = new Point(8 * 50, 4 + i * 30);
i += 2;

public Form1()
Load += Form1_Load;