Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $FileDate = Get-Date
- $SmtpServer = 'smtp.office365.com'
- $SmtpUser = 'blah@blah.com'
- $smtpPassword = 'blah'
- $MailtTo = 'blah@blah.com'
- $MailFrom = 'blah@blah.com'
- $MailSubject = "The file for $FileDate is attached."
- $MailBody = "Please take action"
- $attachment= "C:Usersmy usermyfile.txt"
- $attach = new-object Net.Mail.Attachment ($attachment)
- $Credentials = New-Object System.Management.Automation.PSCredential -
- ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -
- AsPlainText -Force)
- Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -
- Body $MailBody -SmtpServer $SmtpServer -UseSsl -Credential $Credentials -
- attachments "$attach"
- Send-MailMessage : Could not find file
- 'C:UsersmyuserSystem.Net.Mail.Attachment'.
- At line:1 char:1
- + Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -
- Body $ ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : NotSpecified: (:) [Send-MailMessage],
- FileNotFoundException+ FullyQualifiedErrorId :
- System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage
Add Comment
Please, Sign In to add comment