Two Ways To Verify SMTP Settings — Powershell and Console Application(.net core 3.1)

Steven(Liang) Chen
4 min readNov 1, 2020

There are chances that you have been assigned with a new SMTP setting but you do not know if it is valid or not. In this article, I would like to share two ways to verify the SMTP settings

Photo by Mirciov Dan on Unsplash

Table of content

  • What is SMTP
  • Verify by Powershell commend
  • Verify by Console Application(.net core)
  • Summary
  • Reference

What is SMTP

SMTP stands for Simple Mail Transfer Protocol. When we talk about SMTP then IMTP should be mentioned as well:

  • SMTP normally take charge of sending emails and
  • IMTP take charge of receiving emails
SMTP Example

Let’s look at this senirio: suppose you would to send a email from the gmail to iCloud account then the steps should be:

  1. use SMTP to send email to Gmail server
  2. Gmail server forward the email to iCloud server by using SMTP
  3. After lookup the record in the server database then email will be sent to destination by using IMAP

Maybe you also heard of another protocol called POP3 but it is the older version of IMAP and it is rarely used these days.

Both SMTP and IMAP belong to TCP/IP

Verify by Powershell Command

Now let’s look at how to quickly verify if a SMTP is valid or not. If you are unfamiliar with powershell then it is a very powerful command line tool.

Powershell vs cmd:

  • CMD is designed for general users mostly from non-technical background.
  • Powershell is designed for professionals as we can directly call .net libraries from by using it. Also powershell is very popular among devops

Given powershell can directly call .net libraries which is the reason why we can verify SMTP by using it.

Send-MailMessage -from test@test.com -to test1@test.com -Subject "Test" -Body "Test Email" -SmtpServer mail.xxxx.com

This is an example of sending email by using smtp settings from powershell. Once you provide valid information then you will be able to send the email to destination account.

If the email is not sent then it means your smtp settings is invalid.

For more information you can visit this page from the official website.

Verify SMTP by Console Application(.net core)

In this post I will use .net core to demonstrate this example.

Although the we can find SmtpClient in the official website but it is marked as obsolete.

The following link explain why SmtpClient is marked as obsolete. We will not dive too deep in this.

Given SmtpClient is marked as obsolete and MailKit is the successor so that we will use MailKit

You can install MailKit like this:

dotnet add package MailKit
code example

Once you successfully send the email message by using this code, it means your smtp setting is correct. Congratulation!!!

Photo by Wil Stewart on Unsplash

Summary:

In this article we go through what is SMTP and how we verify and send emails by using the SMTP settings that you have.

Hope you like his article. Let me know if you find anything wrong.

References:

https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netcore-3.1

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7

https://github.com/dotnet/dotnet-api-docs/issues/2986

https://github.com/jstedfast/MailKit

--

--