I have a snippet of Powershell code that allows me to specify a filename and path to attach a file into my email I want to send. The code works fine, but I do not wish to use $fileNameAndPath and want to provide raw binary data (in combination with mime type, if applicable).
# Attach file and send SMTPMessage
$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath)
$SMTPMessage.Attachments.Add($attachment)
$SMTPClient.Send($SMTPMessage)
Suppose binary data is stored in $binary, and the mime type is stored in $mimetype. How can pass or convert them so that I can make a System.Net.Mail.Attachment object? Can anyone help me with a snippet ?