Site icon Krum Cheshmedjiev

How to send email from PowerShell using Pegasus Mail

PowerShell, PHP and WSL terminal examples returning accepted_by_pegasus

Three supported ways to submit plain-text email through Pegasus Bridge.

You can send plain-text email from Windows PowerShell through a running Pegasus Mail client by using Pegasus Bridge. The included PowerShell client submits the message to an authenticated local API; Pegasus Bridge validates it and passes it to Pegasus Mail. Your script does not need to store a separate SMTP password.

Important: Pegasus Bridge is not an SMTP server. Pegasus Mail and Pegasus Bridge must be running as the same signed-in Windows user. The identity currently selected in Pegasus Mail determines the actual sender.

What you need

During installation, keep the default Loopback only option for ordinary PowerShell use. The bridge listens locally and every send request requires the random access token created by Setup.

1. Check that Pegasus Mail is available

Invoke-RestMethod 'http://127.0.0.1:18765/v1/health'

Continue only when the response reports "ok": true and "status": "ready". If it reports pegasus_unavailable, start Pegasus Mail and confirm that both programs run under the same signed-in Windows account.

2. Send a simple message from PowerShell

& 'C:\PMAIL\Pegasus Bridge\clients\send.ps1' `
  -From 'sender@example.com' `
  -To 'recipient@example.com' `
  -Subject 'PowerShell test' `
  -Text 'Hello from PowerShell!' `
  -ReplyTo 'replies@example.com'

Change the path if Pegasus Bridge is installed elsewhere. -ReplyTo is optional; when omitted, it defaults to -From.

3. Send multiple lines and Unicode text

Use a PowerShell here-string when the body contains multiple lines. This keeps real line breaks instead of placing the literal characters \n in the message.

$body = @'
First line

Third line after an empty line
Кирилица след нов ред
'@

& 'C:\PMAIL\Pegasus Bridge\clients\send.ps1' `
  -From 'sender@example.com' `
  -To 'recipient@example.com' `
  -Subject 'PowerShell / Кирилица' `
  -Text $body

Pegasus Bridge 1.0.3 was tested with real line breaks, an empty line and mixed Latin/Cyrillic plain text. The formatting was verified both in Pegasus Mail and after delivery to Outlook.

What the response means

A successful request returns HTTP 202 with the status accepted_by_pegasus. This means Pegasus Mail accepted the validated send operation. It does not prove final delivery: delivery still depends on Pegasus Mail, your mail provider and the recipient's server.

Security notes

Current limitations

Troubleshooting

The health check says pegasus_unavailable

Start Pegasus Mail and verify that it runs under the same Windows user and in the same interactive session as Pegasus Bridge.

The sender address is not the one expected

The active Pegasus Mail identity controls the actual MIME From address. Select the required identity in Pegasus Mail before running the script. The -From value does not remotely switch identities.

The message contains \n instead of new lines

Pass actual line-break characters. The here-string example above is the simplest reliable method for a multi-line PowerShell message.

Use PowerShell with your existing Pegasus Mail setup

Pegasus Bridge costs €19 once, with no subscription, and includes a 14-day money-back guarantee.

See requirements, security details and purchase options →

Exit mobile version