locked
send a file via email using a condition (Powershell Script) RRS feed

  • Question

  • as you show in the example below (CSVfile) i would like to send the PDF file using the path to the appropriate email, to 149 users automatically.
    I like to know how I can do it using a powershell script

    Email	                                  link
    contoso1@***.com	           c:\\desktop\contoso1.pdf
    contoso2@***.com	           c:\\desktop\contoso2.pdf
    

    Best Reagards

    Amir




    • Edited by Amir1989 Thursday, July 25, 2019 8:28 AM
    Thursday, July 25, 2019 7:40 AM

All replies

  • 1..147 | % {

    $file = "C:\desktop\contoso$($_).pdf"

    ....  your code to send e-mail using send-mailmessage cmdlet

    }

    Thursday, July 25, 2019 8:38 AM
  • 1..147 | % {

    $file = "C:\desktop\contoso$($_).pdf"

    ....  your code to send e-mail using send-mailmessage cmdlet

    }

    The CC field is how we send a message to multiple users. With Send-Message we can also us the "To" field for multiple users.

    help send-mailmessage -online


    \_(ツ)_/

    Thursday, July 25, 2019 8:43 AM
  • yeah sure but i guess the OP wants to send different attachment to different email.. so.. your advice doesnt match this scenario imo
    Thursday, July 25, 2019 8:53 AM
  • yeah sure but i guess the OP wants to send different attachment to different email.. so.. your advice doesnt match this scenario imo

    Nope. The CSV example is just odd because the user doesn't know about code, CSV files and email.  He thinks like mopst non-techs that you have to send separate messages to each users.  This is something that new techs are no trained in and that most users don't understand because tyhey think this is how the GUI does it.  The magic all happens on the SMTP server and not the client.


    \_(ツ)_/

    Thursday, July 25, 2019 9:02 AM
  • thats what i mean exactly "send different attachment to different email"
    Thursday, July 25, 2019 9:08 AM
  • thats what i mean exactly "send different attachment to different email"

    that isn't what you posted.

    You need to read the CSV in a loop and use the properties to address each message. I posted the CmdLet help.  Now get help on how to use loops.'

    Here is a basic tutorial on how to use PowerShell: https://channel9.msdn.com/Series/Getting-Started-with-Microsoft-PowerShell?l=r54IrOWy_2304984382


    \_(ツ)_/

    Thursday, July 25, 2019 9:23 AM
  • Please everybody. Stop being sorry and think. Computers ae about learning how to think about what you are doing. Think clearly. Understand your problem and explain it carefully and accurately.

    How to ask questions in a technical forum


    \_(ツ)_/

    Thursday, July 25, 2019 11:46 AM
  • Hello Amir,

    you can use below script block to send email, just complete Send-MailMessage command:

    $csvInfo=import-csv <csv file path>
    foreach($row in $csvInfo)
    {
      $to_Email= $row.email
      $file_To_Be_Attached =$row.link
      #use above variables in your Send-MailMessage Command
      Send-MailMessage -Attachments $file_To_Be_Attached -To $to_Email #<and other required parameters>
    }

    Thursday, July 25, 2019 2:27 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, July 31, 2019 6:36 AM