Powershell to send email with attachment only if file is full

  • That's what I was trying to point out but I guess I didn't phrase it correctly.

    Get-Item, when looking for file info, should be your friend.

  • I tried running your code on Windows Powershell ISE and it gives me following error:

    Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed.

    At line:3 char:17

    + Send-MailMessage <<<< -To "email address1" -From "email address 2" -Subject "test mail" -body "sending test mail " -Attachments "filepath\fit_exchange_rate__ex

    ception.csv" -SmtpServer "smtp connection name"

    + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException

    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

    Can you suggest me what could possibly be the error?

  • kpmandani (11/30/2016)


    I tried running your code on Windows Powershell ISE and it gives me following error:

    Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed.

    At line:3 char:17

    + Send-MailMessage <<<< -To "email address1" -From "email address 2" -Subject "test mail" -body "sending test mail " -Attachments "filepath\fit_exchange_rate__ex

    ception.csv" -SmtpServer "smtp connection name"

    + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException

    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

    Can you suggest me what could possibly be the error?

    You are better off making a new thread if you really need help. The error is because you just copy/pasted the command provided which is not going to work in any environment. Understand how to use the command by checking the help/documentation for it: Get-Help Send-MailMessage -full

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • Hi Shawn, I didn't just copy paste as it is. I did add my own email address, file path and other details. The error was still the same. In the error, I have just edited the details on the path and email address that is being used by my work system

  • kpmandani (1/2/2017)


    Hi Shawn, I didn't just copy paste as it is. I did add my own email address, file path and other details. The error was still the same. In the error, I have just edited the details on the path and email address that is being used by my work system

    OK. The error is associated with the SMTP server you are using. You will have to verify your SMTP server is accessible and/or configured.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply