Home Dashboard Directory Help
Search

Send-MailMessage attachments bug by Shay Levi


Status: 

Active


5
0
Sign in
to vote
Type: Bug
ID: 769401
Opened: 11/1/2012 1:17:50 AM
Access Restriction: Public
1
Workaround(s)
view
2
User(s) can reproduce this bug

Description

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

Path                                                                                                                                                        
----                                                                                                                                                        
D:\


PS> Get-ChildItem D:\SkyDrive\temp *.txt | Send-MailMessage -SmtpServer smtp1 -From me@domain.com -to someone@domain.com -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 me@domain.com ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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 me@domain.com -to someone@domain.com -Subject Testing123
Details
Sign in to post a comment.
Posted by JuneB - MSFT 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?

Thanks,
June
Sign in to post a workaround.
Posted by Shay Levi on 11/1/2012 at 1:18 AM
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 me@domain.com -to someone@domain.com -Subject Testing123