0

Got a really strange problem. In my PowerShell script I use the Send-Mailmessage function;

Send-MailMessage -To $($Row.SubjectID) -From 'test@test.nl' -Subject $($Row.SubjectType) -Body $($Row.MessageData) -SmtpServer 'localhost' -Port 2500
write-Output $($Row.MessageData)

My Output $($Row.MessageData) says;

Hi test2! Account created here is the activation link http://localhost/register/activate.php?token=e8987ecebbf54a2b096ae5fd4af34f50be0eab90a989c69da864221cd49cee92

When I look a mailslurper it displays this:

Hi test2! Account created here is the activation link http://loca=
lhost/register/activate.php?token=3De8987ecebbf54a2b096ae5fd4af34=
f50be0eab90a989c69da864221cd49cee92

Anybody knows why the message is changed?

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    It is mail slurper. You must have the word wrap option set. – jdweng Aug 05 '23 at 15:33
  • 1
    As an aside: `$(...)` is only ever needed in two cases: (a) to embed entire _statement(s)_, notably loops and conditionals, in another statement, and (b) to embed an expression, command, or statement(s) inside `"..."`, an expandable (interpolating) string. Referencing a variable as a whole or one of its properties (and even a method call) requires _no_ enclosure; otherwise, `(...)` is enough for single expressions or commands. While not likely, the unnecessary use of `$(...)` can have side effects - see [this answer](https://stackoverflow.com/a/58248195/45375). – mklement0 Aug 05 '23 at 20:52
  • @jdweng if i use the mail function in PHP mail($email, 'Activate Account', $message, $headers); The output is as excpected: Hi test2! Account created here is the activation link http://localhost/register/activate.php?token=2ca9a2067833373ca80cedda4ab2c221f72d0b390ddb9c2eeb046ca3b513ec89 – Wettham038 Aug 06 '23 at 06:33
  • Try option bodyashtml (or other) https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.3 – jdweng Aug 06 '23 at 09:59
  • @jdweng Thank you for your help! Turned on bodyashtml and fiddled with 'encoding'. Used the parameters below and it works! -BodyAsHtml -Encoding 'bigendianunicode' – Wettham038 Aug 07 '23 at 07:51

0 Answers0