-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailfolder.ps1
29 lines (28 loc) · 1.03 KB
/
emailfolder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$from = "[email protected]"
$sendFolder = "send\" #change as needed
$mailto ="email\emailto.txt" #change as needed
$username = "[email protected]"
$pass = "yourpassword"
$smtpServer = "your-smtp-server-address"
$to = Get-Content -Path "$mailto"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.EnableSsl = $true
$smtp.Port = 587
$msg = new-object Net.Mail.MailMessage
Foreach($row in $to){
$msg.To.Add("$row");
}
$msg.From = "$from"
$msg.BodyEncoding = [system.Text.Encoding]::Unicode
$msg.SubjectEncoding = [system.Text.Encoding]::Unicode
$msg.IsBodyHTML = $true
$msg.Subject = "Scheduled E-mail Attachment"
$msg.Body = "<h2> Here are your daily Report attachments. Thanks! </h2><br><br>Please do not respond to this e-mail, no one will respond."
$items = Get-ChildItem -Path "$sendFolder" -Name
Foreach($item in $items){
$path = $sendFolder + $item
$attach = new-object Net.Mail.Attachment($path)
$msg.Attachments.Add($attach)
}
$smtp.Credentials = New-Object System.Net.NetworkCredential("$username", "$pass");
$smtp.Send($msg)