Email blocked due to attachment content or type

If you find that an email attachment is blocked due to its content or type, which is very common when attempting to send some code or a zip file, the following PowerShell may help:

#create file to send
$source_zip = 'C:\temp\'
$file_to_send = 'C:\temp\yourfile.txt'
[convert]::ToBase64String((Get-Content -path $source_zip -Encoding byte)) | Out-File -FilePath $file_to_send

#extract zip
$file_received = 'C:\temp\yourfile.txt'
$extract_zip = 'C:\temp\'
[System.Convert]::FromBase64String((Get-Content $file_received)) | Set-Content $extract_zip -Encoding Byte

Leave a Reply