question

DanielOvadia avatar image
0 Votes"
DanielOvadia asked ·

PowerShell issue with Send-MailMessage -Attachments txt size different

Hey,

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?

thanks
Regards
Daniel



windows-server-powershell
· 3
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you save the attachment after it's been delivered are the two file sizes the same? If not, what are the differences in content between the two files?

If you were to read both messages using, say, a POP3 e-mail client and you saved the messages in text format, are there differences in the way the attachments are encoded within the message body? E.g., has Outlook used MIME and Send-MailMessage used UUEncoding?

0 Votes 0 ·
DanielOvadia avatar image DanielOvadia RichMatheisen-8856 ·

The File that I send lies on my fileshare, and has 19kb. It is exatly the same file.

So I take the file and move it to my email and send it with outlook and the file that I receive is the same file and has 19kb.

But when using Powersehll and send the same textfile, I receive that txt with 18kb.

The difference in the content after receiving the file is that in the file with 18KB I have all the text in vertical spacing.

And the file after receiving by powersehll wich is 19KB the content is without all the vertical spacing.

So my issue is the when sending by powershell txt something is happen to the txt by powershell.

But what and how can I stop Powersehll touching the content of my file?

It is an attached file, not text in the body of the mail.

0 Votes 0 ·

I don't understand what you mean by "all text in vertical spacing".

Does that mean that, say, a line of text when sent from Outlook looks like this:

The quick brown fox jumped over the lazy dog.

And that same line, when sent using "Send-MailMessage" looks like this:

The
quick
brown
fox
jumped
over
the
lazy
dog.

Or are you referring only to line endings that result in different results? E.g.,

When sent from Outlook:

Hi there!

How are you?

I hope you are well!

But when sent using Send-MailMessage:

Hi there!
How are you?
I hope you are well!

Or is it something different? Perhaps you can attach a small sample if the source file, and the same small section from the file attachment from Outlook and Send-MailMessage?





0 Votes 0 ·
DanielOvadia avatar image
0 Votes"
DanielOvadia answered ·

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')
$Message.Attachments.Add($Attachment)
$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);
}
$SMTPClient.Send($Message)

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered ·

Hi @DanielOvadia ,

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.


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please add some content in vertical spacing and send the attachemnt by outlook and by powershell to reproduce this issue

0 Votes 0 ·