.Net
# GENERATE NEW CERT (RUN ONCE)
$thumbprint = “0FE10549F0278B6B9D14A4C43C72B716479FD41C”
# get existing cert
$existingCertificate = Get-Item -Path Cert:\LocalMachine\My\$thumbprint
# generate a new cert based on the existing one one
$newCertificate = New-SelfSignedCertificate -CloneCert $existingCertificate
# COPY NEW CERT TO TRUSTED ROOT CERT AUTHORITIES STORE
$thumbprint = “0FE10549F0278B6B9D14A4C43C72B716479FD41C”
# get existing cert
$certificate = Get-Item -Path Cert:\LocalMachine\My\$thumbprint
# generate temp password and path
$guid = [Guid]::NewGuid().ToString() | ConvertTo-SecureString -AsPlainText -Force
$path = [System.IO.Path]::GetTempFileName()
# export cert
$certificate | Export-PfxCertificate -FilePath $path -Password $guid
# import cert to Trusted Root Store
Import-PfxCertificate -FilePath $path -Exportable -Password $guid -CertStoreLocation Cert:\LocalMachine\Root
# delete temp cert
Remove-Item -Path $path -Force
# APPLY TO CERT TO SERVICE BUS
$thumbprint = “0FE10549F0278B6B9D14A4C43C72B716479FD41C”
Set-SBCertificate -FarmCertificateThumbprint $thumbprint -EncryptionCertificateThumbprint $thumbprint
Stop-SBFarm # RUN ONCE ON WFM SERVER
Update-SBHost # RUN ONCE ON ALL WFM SERVERS
Start-SBFarm # RUN ONCE ON WFM SERVER, THIS TAKES SEVERAL MINUTES TO RUN
.Net
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
Definition
Namespace:
System.Net.Mail
Assemblies:
System.dll, netstandard.dll, System.Net.Mail.dll
Warning
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
https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netframework-4.8
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”, “joey@friends.com”));
message.To.Add (new MailboxAddress (“joey@friends.com”, “alice@wonderland.com”));
message.To.Add (new MailboxAddress (“Alice”, “alice@wonderland.com”));
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 (“smtp.gmail.com“, 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=”jane@contoso.com,ben@contoso.com”
Then MailboxAddress will not parse it.
It should be converted to this format.
“jane@contoso.com”,
“ben@contoso.com”
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()
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServerclient = new SmtpClient(“smtp.gmail.com“);
mail.From = new MailAddress(“your_email_address@gmail.com”);
mail.To.Add(“to_address”);
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;
SmtpServerclient.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
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()
{
try
{
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(“smtp.gmail.com“, 465, SecureSocketOptions.SslOnConnect);
SmtpServerclient.Authenticate(“username”, “password”);
mail.From = new oldsmtp.MailAddress(“your_email_address@gmail.com”);
mail.To.Add(“your_email_address@gmail.com,your_email_address@gmail.com,your_email_address@gmail.com”);
mail.Subject = “Test Mail – 1”;
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = “Write some HTML code here”;
SmtpServerclient .Send(MimeMessage.CreateFromMailMessage(mail));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
Our Team, Testimonial
SERENE POWERS
Email: serene@trigrealty.com
Phone: +1 646 706 1282
Website
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
Our Team, Testimonial
TRICIA STRIANO
Email: PowersTeam@trigrealty.com
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.
Our Team, Testimonial
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