Send-MailMessage attachments bug - by Shay Levi

Status : 


Sign in
to vote
ID 769401 Comments
Status Active Workarounds
Type Bug Repros 2
Opened 11/1/2012 1:17:50 AM
Access Restriction Public


PS> help Send-MailMessage -Parameter att*

-Attachments <String[]>
    Specifies the path and file names of files to be attached to the e-mail message. You can use this parameter or pipe the paths and file names to Send-MailMessage.

Files piped to Send-MailMessage are bound to the Attachments parameter (which accept ValueFromPipeline and also defines a "PsPath" Alias).
That said, the files we pipe MUST RESIDE in the current working directory, otherwise the files path is not honored. Instead, just the file names are used, concatenated with the working directory path, and the command fails..

PS> pwd


PS> Get-ChildItem D:\SkyDrive\temp *.txt | Send-MailMessage -SmtpServer smtp1 -From -to -Subject Testing123

Send-MailMessage : Could not find file 'D:\Document1.txt'.
At line:1 char:30
+ Get-ChildItem D:\SkyDrive\temp *.txt | Send-MailMessage -SmtpServer smtp1 -From ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Send-MailMessage], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage

As a workaround we can first set the current working location to directory where the files are located.

PS>Set-Location  D:\SkyDrive\temp
PS> dir *.txt | Send-MailMessage -SmtpServer smtp1 -From -to -Subject Testing123
Sign in to post a comment.
Posted by June Blender on 11/16/2012 at 10:47 AM
Thanks, Shay, but I can't reproduce this on Windows 8 or Windows Server 2012. I was even able to pipe a file from a UNC drive to a mail message.

Can you please add your $psversiontable? If this is an upgrade, it would be useful to know the upgrade path, e.g. were there preview versions on this machine?