1

I'm getting the following errors when trying to send an email to a recipient with extended ASCII characters, on my Postfix server, using PowerShell or the System.Web.Mail.SmtpMail .NET class:

The client or server is only configured for E-mail addresses with ASCII local-parts: livelink+264096812$£&@mytenant.onmicrosoft.com

The server rejected one or more recipient addresses. The server response was: 500 5.5.2 Error: bad UTF-8 syntax

The british pound sign "£" is most probably the culprit, as it is the only non 7-bit/extended ASCII char.

I've searched high and low for practical examples of how to use extended-ASCII chars in recipient addresses, but nothing seems to work. I know it's doable since I can send an email successfully to that mailbox from Outlook. But I can't from a PowerShell command line. My Postfix server is up-to-date and configured with 8BITMIME and SMTPUTF8 support.

I would greatly appreciate some help !

geoced
  • 693
  • 3
  • 16

1 Answers1

1

For those having the same issue, I was able to send an email to a non-ASCII recipient by forcing the use of SMTPUTF8 in my SMTP client. In my case, I had to use the System.Net.Mail .NET class in a PowerShell function, since neither the built-in Send-MailMessage cmdlet nor the System.Web.Client class offer this option (and both are deprecated anyway).

    $smtpClient = [System.Net.Mail.SmtpClient]::new()
    $smtpClient.Host = $SmtpServer
    $smtpClient.Port = $Port
    $smtpClient.EnableSsl = $Port -eq 587
    $smtpClient.DeliveryFormat = [System.Net.Mail.SmtpDeliveryFormat]::International

    $mailMessage = [System.Net.Mail.MailMessage]::new()
    $mailMessage.From = [System.Net.Mail.MailAddress]::new($Sender)
    $mailMessage.To.Add($RecipientList)
    $mailMessage.Subject = $Subject
    $mailMessage.SubjectEncoding = [System.Text.Encoding]::UTF8
    $mailMessage.Body = $newBody
    $mailMessage.BodyEncoding = [System.Text.Encoding]::UTF8
    $mailMessage.IsBodyHtml = $BodyAsHtml.IsPresent

    try {
        $smtpClient.Send($mailMessage)
        Write-Output "Message successfully sent to $RecipientList from $Sender on ${SmtpServer}:$Port"
    } catch [System.Exception] {
        $PSCmdlet.ThrowTerminatingError($_)
    }

It's also possible with MailKit

geoced
  • 693
  • 3
  • 16