Sending email with binary attachments

Hi, I am trying to develop an automation script that will send an Excel file (.xlsx) to our team. However, during my tests, it seems that the attachments are being converted into text file. As this is my first time trying to use PowerShell to send email, I am not sure whether this is due to our SMTP server setting, or this is the Send-MailMessage cmdlet default.

The test command I have been testing so far:

$mailcred = Get-Credential myusername
$myfile = "C:\Temp\testfile.xlsx"
Send-MailMessage -From "" -to "" -Subject "Test email from PowerShell cmdlet with attachment" -Body "This is a test email" -Attachments $myfile -Credential $mailcred -SmtpServer '' -Port 25 -UseSsl

Are there additional steps I need to do first to be able to send binary file attachments using the Send-MailMessage cmdlet? So far, what I have seen mostly examples in the web are attachments with .txt and .csv files.

Thanks for the advise in advance!



Roose, welcome to Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code, error messages, sample data or console output format it as code, please.
In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
Thanks in advance.

The cmdlet doesn’t do any conversions. The code can be used to attach any type of file that I’m aware of just as you would do in a mail client. If the attachment is being stripped, then it’s most likely a SPAM filter or something. The examples of csv and txt are typically supplementing reporting information from Powershell. While you can use HTML to make a nice report email, if there is a list of 100 users, then you would typically attach that as a CSV or TXT.