- September 27, 2020
- Posted by: Syed Shujaat
- Category: Uncategorized
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.
>> helo aol.com >> mail from:[add space]xyz@domain.com >> rcpt to:[add space]abc@aol.com
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.
- Open Windows Command Prompt using Start > Command Prompt or via Run > CMD
- Telnet to the mail server by typing telnet <domain> 25
- 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. - Now we must set the sending mail address. Type mail from:<email address>
- Now we set the to address. Type RCPT TO:<email address>
- Type data to begin the email content.
- First we set the subject by typing Subject:<Your Subject> Then press Enter twice.
- Now type the message content of your email. When done, press Enter – Period Key – Enter to close the message.
- Type Quit to exit telnet.
- Verify your email has been received.