Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Connection Details
- $username=”xxxx”
- $password=”xxxx”
- $smtpServer = “smtp-relay.gmail.com”
- $msg = new-object Net.Mail.MailMessage
- #Change port number for SSL to 587
- $smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
- #Uncomment Next line for SSL
- $smtp.EnableSsl = $true
- $smtp.Credentials = New-Object System.Net.NetworkCredential( $username, $password )
- #From Address
- $msg.From = "xxxx"
- #To Address, Copy the below line for multiple recipients
- $msg.To.Add(“xxxx”)
- $msg.To.Add(“xxxx”)
- #Message Body
- $msg.Body=”Please See Attached Files”
- #Message Subject
- $msg.Subject = “Email with Multiple Attachments”
- #your file location
- $files=Get-ChildItem “C:\xxxx\xxxx”
- Foreach($file in $files)
- {
- Write-Host “Attaching File :- ” $file
- $attachment = New-Object System.Net.Mail.Attachment –ArgumentList C:\xxxx\xxxxx\$file
- $msg.Attachments.Add($attachment)
- }
- $smtp.Send($msg)
- $attachment.Dispose();
- $msg.Dispose();
- Remove-Item "C:\xxxx\xxxx\*.*"
Add Comment
Please, Sign In to add comment