Test SMTP on Telent 25 / Office 365 port 587 Powershell

Firstly open up Powershell (Must be v3 or greater), then copy/paste the following command,

$creds = get-credential 

When prompted, enter the Office 365 username and password which you plan to run the test from.

Once these credentials are stored in a variable, copy and paste the next snippet replacing the FROM field with your Office365 account that you have just specified in your credentials then specify a valid TO address,

Send-MailMessage –From <O365 email address> –To <Recipient email address> –Subject "Test Email" –Body "Test SMTP Service from Powershell on Port 587" -SmtpServer smtp.office365.com -Credential $creds -UseSsl -Port 587

All being well the email should be successfully delivered.

If you get the following error message when running the command, you need to ensure you are running Powershell version 3 or greater

Send-MailMessage : A parameter cannot be found that matches parameter name ‘Port’.

Sample Script:

==================================================================

# Get the credential

$credential = Get-Credential

## Define the Send-MailMessage parameters

$mailParams = @{

SmtpServer = ‘smtp.office365.com’

Port = ‘587’

UseSSL = $true

Credential = $credential

From = ‘jim@xyz.com’

To = ‘tom@abc.com’

Subject = “SMTP Client Submission – $(Get-Date -Format g)”

Body = ‘This is a test email using SMTP Client Submission’

}

## Send the message

Send-MailMessage @mailParams

=====================================================

Test SMTP using TELNET 

You can also use Telnet Because O365 uses TLS You can’t really get far using Telnet on its own besides connecting to the server.

To provide the Username and Password you then have to use base64 encryption and then you could go one step further if you wanted to persevere.
From the command prompt
>> Telnet IP@ 25
>> helo aol.com
>> mail from:[add space]xyz@domain.com 
>> rcpt to:[add space]abc@aol.com
>>Data <hit enter>
!! you will see this message :354 Start mail input:end with <CRLF>.<CRLF>
This is my test mail. [must end your message with period] <hit enter>
>>subject: This is just a test <hit enter>
[put another period] ! this will send queu your message. ! go to IIS Manager current sessions to see your message getting queued.
… Check your mailbox, you should receive the mail if everything goes fine..
Here is the syntax which worked for me. 
telnet 192.168.xx.x 25

220 MSHQ2 Microsoft ESMTP MAIL Service, Version: 10.0.14393.4169 ready at Thu,
22 Apr 2021 15:40:06 -0700
helo me
250 MSHQ2 Hello [192.168.xx.xx]
mail from: mickymouse@abc.com
250 2.1.0 mickymouse@abc.com….Sender OK
rcpt to: tomjerry@xyz.com
250 2.1.5 tomjerry@xyz.com
data
354 Start mail input; end with <CRLF>.<CRLF>
Please work this time.
subject: This is a test
.
250 2.6.0 <MSHQ2FRaqbC8wSA1Xvp00000002@MSHQ2> Queued mail for delivery
451 Timeout waiting for client input

Connection to host lost.

How To Send Email Locally Using Command Prompt
This article serves as a guide to test simple email functionality on your server if you are unable to access your SmarterMail interface.
  1. Open Windows Command Prompt using Start > Command Prompt or via Run > CMD
  2. Telnet to the mail server by typing telnet <domain> 25
  3. Once connected, we must initiate the mail sending process queue.  We start this with helo <domain>

    The server will reply with 250 and a hello if successful.
  4. Now we must set the sending mail address.  Type mail from:<email address>
  5. Now we set the to address.  Type RCPT TO:<email address>
  6. Type data to begin the email content.
  7. First we set the subject by typing Subject:<Your Subject> Then press Enter twice.
  8. Now type the message content of your email.  When done, press Enter – Period Key – Enter to close the message.
  9. Type Quit to exit telnet.
  10. Verify your email has been received.