Email attachment of Excel Spreadsheet inside of Outlook via Powershell RRS feed

  • Question

  • I appear to be stuck when trying to import a spreadsheet into email during a powershell script.

    Here is what I have so far. Can someone tell me what I'm missing?

    Bottom half of the script is the attempted email portion.

    #Function to send email with an attachment

    Function sendEmail([string]$emailFrom, [string]$emailTo, [string]$subject,[string]$body,[string]$smtpServer,[string]$filepath)
    #initate message
    $email = New-Object System.Net.Mail.MailMessage
    $email.From = $emailFrom
    $email.Subject = $subject
    $email.Body = $body
    #initiate email attachment

    $emailAttach = New-Object System.Net.Mail.Attachment $filepath


    #initiate sending email
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)

    #Call Function
    sendEmail -emailFrom $from -emailTo $to  -subject "Encryption Weekly Report $enddate" -body $email -smtpServer $SMTP -filePath $filepath

    Tuesday, December 8, 2015 9:38 PM


All replies