Find us on social media
SMTPEmailRelay7 min read
Configure SMTP relay for sending emails
Configure an SMTP relay on Windows Server so your applications can send emails.
An SMTP relay allows your applications to send emails through an external mail server.
Step 1 — Install the IIS SMTP service
powershell
Install-WindowsFeature SMTP-Server -IncludeManagementToolsStep 2 — Configure the SMTP server
Open IIS 6 Manager:
powershell
# Open the SMTP management console
inetmgr6.exeIn the console:
- Expand the server > SMTP Virtual Server
- Right-click > Properties
- On the Access tab > Relay > add 127.0.0.1
- On Delivery > Smart Host > enter your external SMTP server
Step 3 — Configure relay with PowerShell
powershell
# Configure smart host (external relay)
$smtp = [ADSI]"IIS://localhost/SmtpSvc/1"
$smtp.SmartHost = "smtp.yourprovider.com"
$smtp.SmartHostType = 2
$smtp.SetInfo()Step 4 — Use Send-MailMessage (simple method)
To send emails directly from PowerShell:
powershell
$params = @{
From = "server@mydomain.com"
To = "admin@mydomain.com"
Subject = "Server Alert"
Body = "The backup completed successfully."
SmtpServer = "smtp.gmail.com"
Port = 587
UseSsl = $true
Credential = (Get-Credential)
}
Send-MailMessage @paramsStep 5 — Configure with hMailServer (alternative)
Download and install hMailServer for a complete SMTP server:
powershell
# After installing hMailServer
# Configure relay in the admin interface:
# Settings > Protocols > SMTP > Delivery of email
# Smart host: smtp.yourprovider.com
# Port: 587
# Authentication: provider username and passwordStep 6 — Configure applications to use the relay
In your application, configure SMTP pointing to localhost:
terminal
SMTP Server: 127.0.0.1
Port: 25
Authentication: None (local relay)Step 7 — Test sending
powershell
# Quick test with telnet
Test-NetConnection -ComputerName 127.0.0.1 -Port 25
# Send test email
Send-MailMessage -From "test@mydomain.com" -To "you@email.com" -Subject "Test" -Body "It works" -SmtpServer 127.0.0.1Step 8 — Firewall
powershell
# Only allow SMTP from localhost
New-NetFirewallRule -DisplayName "SMTP Local" -Direction Inbound -Protocol TCP -LocalPort 25 -RemoteAddress 127.0.0.1 -Action AllowWith the SMTP relay configured, your applications on the Baires Host Windows VPS can send notifications and alerts via email.
Was this guide helpful?