PowerShell issue with Send-MailMessage -Attachments txt size different

Daniel Ovadia 121 Reputation points


I have a strange issue...

Send-MailMessage -to 'mail@maildomain.de' -from 'mail2@maildomain.de' -Attachments "\uncpath\testfile.txt" -Subject "test" -SmtpServer mysmtphost

The File Size of my txt is 19kb, when sending by outlook client it keeps 19kb.

When sending by Powershell script the filesize is 18kb.

I tried with params like utf8 encoding, bodyashtml and so on..but everytime the txt file was send by PS it changes something.

How can I tell Powersehll sending the file attachment without making any changes like outlook client?


Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,453 questions
{count} votes

Accepted answer
  1. Daniel Ovadia 121 Reputation points

    Actually I found a workaround. Sharing is caring :)
    I use a part of robocopy, which is for logfiles but can send txt aswell.
    Howeever this is my script

    Send E-mail message with log file attachment

    $Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)
    $Attachment = New-Object Net.Mail.Attachment($Logfile, 'text/plain')
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
    If (-not $SMTPPort -eq "25"){
    $SMTPClient.EnableSsl = $true;
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 34,111 Reputation points Microsoft Vendor

    Hi @Daniel Ovadia ,

    I sent a txt file using the Send-MailMessage cmdlet and the hash values of the two files are identical. Can you check what the differences are between your two files?

    Best Regards,
    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.