• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

powershell sending email alert automatically attaches winmail.dat

Greetings,

We are using powershell scripts to email out notifications for windows server 2012 backups. However when sending the message, it is attaching a file winmail.dat automatically, which is causing some email providers to reject the message thinking its spam / virus related. How can we stop this attachment from sending? Here is the script we are using:

# Set up variables
$SmtpServer = "SMTP SERVER ADDRESS"
$SmtpPort = 25
$FromEmail = "FROM EMAIL ADDRESS"
$ToEmail = "TO EMAIL ADDRESS"

# Construct and send email
$SmtpClient = new-object system.net.mail.smtpClient
$Msg = new-object Net.Mail.MailMessage
$SmtpClient.host = $SmtpServer
$SmtpClient.Port = $SmtpPort
$computer = gc env:computername
$Msg.From = $FromEmail
$Msg.To.Add($ToEmail)
$Msg.Subject = "Company Name Windows Server Backup Successful on " +$Computer + ""
$Msg.Body = "The backup for " +$Computer+" has completed successfully."
$SmtpClient.Send($Msg)
0
cerhelp
Asked:
cerhelp
  • 10
  • 9
1 Solution
 
Cliff GaliherCommented:
Winmail.dat is how some multipart messages get processed by sending servers (most notably exchange) when the initial sender does not properly declare mime types or the formatting is invalid. My inclination  is that one of your variables is an object type that is causing problems,  but would need to analyze the working/running environment to say more. The Powershell ISE should make quick work of troubleshooting though.
0
 
cerhelpAuthor Commented:
I tagged the question incorrectly. This is server 2008. We added the feature to run ISE. However we have limited knowledge of powershell scripting. Is there something specific that we should be looking for? Or perhaps is there an alternate syntax / commands that could work better? Also is there a command line we can use to try to set a standard MIME type to test?
0
 
SubsunCommented:
Try using Send-MailMessage and see if there any difference..
# Set up variables
$SmtpServer = "SMTP SERVER ADDRESS"
$FromEmail = "FROM EMAIL ADDRESS"
$ToEmail = "TO EMAIL ADDRESS"
$computer = gc env:computername
Send-MailMessage -From $FromEmail -To $ToEmail -Body "The backup for $Computer has completed successfully." -Subject "Company Name Windows Server Backup Successful on $Computer" -SmtpServer $SmtpServer

Open in new window

0
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
cerhelpAuthor Commented:
Same thing happens, still getting the winmail.dat attachment when coming into webmail providers.
0
 
SubsunCommented:
What if you send the mails as HTML?
Send-MailMessage -From $FromEmail -To $ToEmail -BodyAsHtml "The backup for $Computer has completed successfully." -Subject "Company Name Windows Server Backup Successful on $Computer" -SmtpServer $SmtpServer

Open in new window

0
 
cerhelpAuthor Commented:
still exhibits the same behavior. thank you in advanced for your assistance
0
 
SubsunCommented:
What if you try with -Encoding parameter? For example..
Send-MailMessage -From $FromEmail -To $ToEmail -Body "The backup for $Computer has completed successfully." -Subject "Company Name Windows Server Backup Successful on $Computer" -SmtpServer $SmtpServer -Encoding ASCII

Open in new window


For more details on -Encoding parameter, refer the following article..
http://ss64.com/ps/send-mailmessage.html
0
 
cerhelpAuthor Commented:
I have found a few articles that have mentioned something about TNEF encoding as a possible cause. is there anyway to disable TNEF encoding easily?
0
 
SubsunCommented:
TNEF encoding should be disabled at the server side.. Which Exchange Server version are you using?
0
 
cerhelpAuthor Commented:
We are not running exchange. Just powershell commands for issuing email alerts for backup events. I had found some possible related articles I thought were relevant, but the TNEF I'm assuming is directly for Exchange?
0
 
SubsunCommented:
I am taking about the SMTP server which you specify in the command, do you have information about it?

BTB, TNEF is a proprietary format used by Microsoft Outlook and Microsoft Exchange Server.
0
 
cerhelpAuthor Commented:
Oh my mistake. It is a standard ISP smtp server, through time warner. smtp-server.stny.rr.com. standard ports 25 ssl 587, no spa, no smtp authentication. Thats about all i have.
0
 
SubsunCommented:
In that case you can to test by adding -Encoding parameter as i mentioned in ID: 40277164. If it doesn't work, then nothing much can be done from your end. You need to contact the service provider to fix the issue..
0
 
cerhelpAuthor Commented:
oh i somehow missed that. When trying that method it results in the following error:


Send-MailMessage : Cannot bind parameter 'Encoding'. Cannot convert the "ASCII" value of type "System.String" to type "System.Text.Enco
ding".
At D:\Tech\Scripts\successemail.ps1:6 char:212
+ Send-MailMessage -From $FromEmail -To $ToEmail -Body "The backup for $Computer has completed successfully." -Subject "Company Name Wi
ndows Server Backup Successful on $Computer" -SmtpServer $SmtpServer -Encoding <<<<  ASCII
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SendMailMessage
0
 
SubsunCommented:
Try..
 -Encoding ([System.Text.Encoding]::ASCII)

Open in new window

0
 
cerhelpAuthor Commented:
I found an article which stated changing the encoding bit from

 "-Encoding ASCII"

 to

 "-Encoding ([System.Text.Encoding]::ASCII)"

would resolve the error. It is now sending successfully again, however the winmail.dat file remains. I guess it may actually just be an ISP issue, unless this response opens any other avenues to explore.
0
 
cerhelpAuthor Commented:
Just for informational purposes, also attempted UT8 encoding using

$enc  = New-Object System.Text.utf8encoding

and then swapping out adding $enc after -encoding. same results, sends but still has winmail.dat
0
 
SubsunCommented:
You can also try other encoding to see if it eliminate your problem...

like..

[System.Text.Encoding]::Unicode

[System.Text.Encoding]::UTF8

Yes, it should be an ISP issue, and we tried all our options to find a workaround for the problem..
0
 
SubsunCommented:
OK. so the encoding doesn't have any effect on email issue.. I don't see any other option which you can try now, other than contacting your ISP..
0
 
cerhelpAuthor Commented:
ok, thank you very much for your assistance, we will have to just set them up with a different email address. efforts with our isp will be fruitless.
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now