locked
Sending text within a document RRS feed

  • Question

  • I am looking to import text into a e-mail from a document. For example, If I have a document called text1.txt and instead of me having to send it as an attachment and open it up. Is their anyway I can just import that text into the e-mail so I dont have to open it every time?

    I have the code for sending an e-mail but I am not sure how to export text from inside a document. Is this possible?

    Thanks!
    Wednesday, July 30, 2014 4:09 PM

Answers

  • I think you will want to do something like this:

    $mail.Body = (Get-Content "myFileName")

    • Proposed as answer by atom_acres Wednesday, August 27, 2014 1:28 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 7:21 PM
    Wednesday, July 30, 2014 7:43 PM

All replies

  • I have the code for sending an e-mail but I am not sure how to export text from inside a document. Is this possible?

    Yes, it is possible. Let's have a look at your code!
    Wednesday, July 30, 2014 4:20 PM
  • Sure thing, it looks like this

    $EmailFrom = "email1@gmail.com"
    $EmailTo1 = "email2@gmail.com"
    $EmailTo2 = "email3@gmail.com"
    $EmailTo3 = "email4@bmail.com"
    $EmailTo4 = "email5@gmail.com"
    $EmailSubject = "Errors"  
    $EmailBody = "See Attached."
      
    $SMTPServer = "smtpserver"
    $emailattachment = "location"
    
    function send_email {
    $mailmessage = New-Object system.net.mail.mailmessage 
    $mailmessage.From = ($EmailFrom) 
    $mailmessage.To.add($EmailTo1)
    $mailmessage.To.add($EmailTo2)
    $mailmessage.To.add($EmailTo3)
    $mailmessage.To.add($EmailTo4)
    $mailmessage.Subject = $EmailSubject
    $mailmessage.Body = $EmailBody
    $attachment = New-Object System.Net.Mail.Attachment($emailattachment)
    $mailmessage.Attachments.Add($attachment)
    
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, port#)  
    $SMTPClient.Send($mailmessage)
    }
    
    send_email
    

    Wednesday, July 30, 2014 5:35 PM
  • I think you will want to do something like this:

    $mail.Body = (Get-Content "myFileName")

    • Proposed as answer by atom_acres Wednesday, August 27, 2014 1:28 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 7:21 PM
    Wednesday, July 30, 2014 7:43 PM