locked
Sending email attachments RRS feed

  • Question

  • Hello everyone
    I'm new with PS. I'm able to attach a single known file or copy content of mupltiple into new one and send it via email but I really wonder how to add attachments separately, let's say, every *.txt file from a folder  by using
    $Message.Attachments.Add()
    but still can't figure it out.   Could someone help me please?


    • Edited by vladeasy Thursday, May 17, 2018 9:42 AM
    Thursday, May 17, 2018 9:41 AM

Answers

  • $attachments = Get-ChildItem c:\temp\*.txt | select -expand fullname


    \_(ツ)_/

    • Marked as answer by vladeasy Thursday, May 17, 2018 10:51 AM
    Thursday, May 17, 2018 10:17 AM

All replies

  • Send-MailMessage -To xxxx -From xxx  -Attachments a.txt,b.txt,c.txt ….

    help Send-MailMessage -online

    Follow the examples in the help


    \_(ツ)_/

    Thursday, May 17, 2018 9:48 AM
  • My question is about how to  send any .txt file, i mean unknown, that stores in a folder, exact ones are pretty simple
    Thursday, May 17, 2018 9:54 AM
  • What does that mean?  You cannot attach folder to a message.  With email you can only attach files.


    \_(ツ)_/

    Thursday, May 17, 2018 9:57 AM
  • Sorry for my english. Let's say we have several .txt in a single folder and we do not know their names. I wonder how to attach each one to a message
    Thursday, May 17, 2018 10:01 AM
  • $attachments = Get-ChildItem c:\temp\*.txt | select -expand fullname


    \_(ツ)_/

    • Marked as answer by vladeasy Thursday, May 17, 2018 10:51 AM
    Thursday, May 17, 2018 10:17 AM
  • This sends email with proper attachments but works with an error. It says "Add" cannot be undefined. In this case i have no idea how to get files dynamically.  I'm looking for something nearly like this, thanks

    $Attachments = Get-ChildItem c:\temp\*.txt | select -expand fullname
    for($i=0; $i -le $Attachments.Count; $i++){
    $Message.Attachments.Add($Attachments[$i])}


    • Edited by vladeasy Thursday, May 17, 2018 10:51 AM
    Thursday, May 17, 2018 10:49 AM