Notice: Due to size constraints and loading performance considerations, scripts referenced in blog posts are not attached directly. To request access, please complete the following form: Script Request Form Note: A Google account is required to access the form.
Disclaimer: I do not accept responsibility for any issues arising from scripts being run without adequate understanding. It is the user's responsibility to review and assess any code before execution. More information

Powershell: SMTP Rapid Fire 🔥

⚠️

Important: Please honor email etiquette and use this script responsibly. Only for legitimate testing with your own email addresses and do not abuse sending limits

When developing email functionality in applications, developers often need to test how their systems handle multiple email sends. Whether you're building an email notification system, testing SMTP configurations, or validating email delivery mechanisms, having a reliable testing script can be invaluable.


The Testing Script

The script includes configurable variables for message count and timing, along with proper error handling and logging.

Key Features

  • Configurable message count and delays: Easily adjust the number of test emails and timing between sends
  • Error handling: Robust error reporting for troubleshooting connection issues
  • Progress tracking: Real-time feedback on email sending status

Script: SMTP-RapidFire.ps1

# PowerShell Email Testing Script
# WARNING: Use responsibly - only for legitimate testing purposes

# Configuration Variables
$NumberOfMessages = 32
$DelayBetweenMessages = 5  # Seconds
$SMTPServer = "smtp.bear.local"
$SMTPPort = 25
$From = "rapid.fire@bear.local"
$To = "authorized.user@bear.local"
$Subject = "Rapid Testing"
$Body = "Rapid Testing Test"

# Function to send email
function Send-TestEmail {
    param(
        [string]$SMTPServer,
        [int]$SMTPPort,
        [string]$From,
        [string]$To,
        [string]$Subject,
        [string]$Body,
        [int]$MessageNumber
    )
    
    try {
        # Create mail message
        $Message = New-Object System.Net.Mail.MailMessage
        $Message.From = $From
        $Message.To.Add($To)
        $Message.Subject = "$Subject - Message $MessageNumber"
        $Message.Body = "$Body - Message $MessageNumber sent at $(Get-Date)"
        
        # Create SMTP client
        $SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
        $SMTPClient.EnableSsl = $false  # Set to $true if SMTP server requires SSL
        
        # Send the email
        $SMTPClient.Send($Message)
        
        Write-Host "Message $MessageNumber sent successfully at $(Get-Date)" -ForegroundColor Green
        
        # Clean up
        $Message.Dispose()
        $SMTPClient.Dispose()
        
        return $true
    }
    catch {
        Write-Host "Failed to send message $MessageNumber : $($_.Exception.Message)" -ForegroundColor Red
        return $false
    }
}

# Main execution
Write-Host "Starting email test sequence..." -ForegroundColor Yellow
Write-Host "Number of messages: $NumberOfMessages" -ForegroundColor Yellow
Write-Host "Delay between messages: $DelayBetweenMessages seconds" -ForegroundColor Yellow
Write-Host "SMTP Server: $SMTPServer" -ForegroundColor Yellow
Write-Host "From: $From" -ForegroundColor Yellow
Write-Host "To: $To" -ForegroundColor Yellow
Write-Host ""

$SuccessCount = 0
$FailureCount = 0

for ($i = 1; $i -le $NumberOfMessages; $i++) {
    Write-Host "Sending message $i of $NumberOfMessages..." -ForegroundColor Cyan
    
    $Result = Send-TestEmail -SMTPServer $SMTPServer -SMTPPort $SMTPPort -From $From -To $To -Subject $Subject -Body $Body -MessageNumber $i
    
    if ($Result) {
        $SuccessCount++
    } else {
        $FailureCount++
    }
    
    # Wait before sending next message (except after the last message)
    if ($i -lt $NumberOfMessages) {
        Write-Host "Waiting $DelayBetweenMessages seconds before next message..." -ForegroundColor Yellow
        Start-Sleep -Seconds $DelayBetweenMessages
    }
}

Write-Host ""
Write-Host "Email test sequence completed!" -ForegroundColor Green
Write-Host "Successfully sent: $SuccessCount messages" -ForegroundColor Green
Write-Host "Failed to send: $FailureCount messages" -ForegroundColor Red

Configuration of the Script

Before running the script, update these essential variables:

  • $NumberOfMessages: Set to a reasonable number for testing (recommend 2-5 max)
  • $DelayBetweenMessages: Use appropriate delays (60+ seconds minimum)
  • $SMTPServer: Your SMTP server address
  • $SMTPPort: SMTP port (usually 25, 587, or 465)
  • $From: Sender email address
  • $To: Recipient email address (use your own for testing

Conclusion

This PowerShell email testing script provides a solid foundation for responsible email testing in development environments. Remember that with great power comes great responsibility – always use email testing tools ethically and considerately.

Previous Post Next Post

نموذج الاتصال