Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Createfile
- {
- $location = "C:\Mailbot\New\"
- $mailgroup = "jrosolen@balmain.com.au"
- $date = (Get-Date).ToString('MM-dd-yyyy')
- $outfile = $location+$date+"test_report.txt"
- $subject = "Test email, date: " + $date
- $mailto = ""
- foreach($mail in $mailgroup){$mailto = $mailto + $mail + ";"}
- $mailto = $mailto.trimend(";")
- $body = "How long can I sit`r`nNursing my coffee until`r`nI have to do work?`r`n`r`nTest Username: T_Test`r`nTest Password: Password"
- $output = $mailto + "`r`n" + $subject + "`r`n" + $body
- $output | out-file $outfile
- }
- Function SendFile
- {
- $filelist = Get-ChildItem -path c:\mailbot\New\ -filter "*.txt" | ForEach-Object {
- $filed = $_.fullname
- $ToField = get-content -path $filed | select-object -first 1
- $Recipients = $ToField -split ";"
- $SubjectField = get-content -path $filed | select-object -Skip 1 | Select-Object -First 1
- $BodyField = get-content -path $filed | select-object -Skip 2 | Out-String
- $Recipients | foreach {
- Write-host "TO: " $_
- }
- Write-host "SUBJECT: " $SubjectField
- Write-host "BODY: " $BodyField
- Send-MailMessage -to $Recipients -from "mailbot@balmain.com.au" -subject $SubjectField -Body $BodyField -SmtpServer "192.168.6.51"
- move-item $filed C:\Mailbot\Archive\
- }
- }
- Sendfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement