Attachment is not being sent via email

This topic contains 2 replies, has 2 voices, and was last updated by  Jatinder Pal Singh 2 months, 1 week ago.

  • Author
    Posts
  • #95883

    Jatinder Pal Singh
    Participant

    Hi Team,

    I am learning powershell and have command where I am sending the email to myself along with the attachment. I am able to send the email but attachment is not being sent. Below is the command:

    PS C:\JPS> Get-Service -Name B* | Export-Csv C:\JPS\test.csv | Send-MailMessage -To myemail@domain.com -Subject
    'Sending Test Attachment' -SmtpServer 'servername' -Attachments test.csv -From myemail@domain.com -Verbose

  • #95886

    Aapeli Hietikko
    Participant

    As far as I know, it won't work from pipeline. Divide that to to commands

    Get-Service -Name B* | Export-Csv C:\JPS\test.csv 
    Send-MailMessage -To jatinder.singh@ihsmarkit.com -Subject
    'Sending Test Attachment' -SmtpServer 'servername' -Attachments C:\JPS\test.csv -From jatinder.singh@ihsmarkit.com
    -Verbose
    

    Or if you want it to be one liner, then

    Get-Service -Name B* | Export-Csv C:\JPS\test.csv ; Send-MailMessage -To jatinder.singh@ihsmarkit.com -Subject
    'Sending Test Attachment' -SmtpServer 'servername' -Attachments C:\JPS\test.csv -From jatinder.singh@ihsmarkit.com
    -Verbose
    
  • #96051

    Jatinder Pal Singh
    Participant

    Yes Aapeli, you were right. Thank you so much. Without using |, it worked.

You must be logged in to reply to this topic.