none
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.To.Add($emailTo)
    $email.Subject = $subject
    $email.Body = $body
    #initiate email attachment


    #$email.Getinspector.ExcelEditor.Range().Paste()
    #$email.Display()
    #$email.Send()
     
    $emailAttach = New-Object System.Net.Mail.Attachment $filepath
    $email.Attachments.Add($emailAttach)
    $email.Getinspector.WordEditor.Range().Paste()


    #$mail.Getinspector.WordEditor.Range().Paste()
    #$mail.Display()
    #$mail.Send()

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

    #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

Answers

All replies