Guest User

Untitled

a guest
Feb 8th, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. $FileDate = Get-Date
  2. $SmtpServer = 'smtp.office365.com'
  3. $SmtpUser = 'blah@blah.com'
  4. $smtpPassword = 'blah'
  5. $MailtTo = 'blah@blah.com'
  6. $MailFrom = 'blah@blah.com'
  7. $MailSubject = "The file for $FileDate is attached."
  8. $MailBody = "Please take action"
  9. $attachment= "C:Usersmy usermyfile.txt"
  10. $attach = new-object Net.Mail.Attachment ($attachment)
  11. $Credentials = New-Object System.Management.Automation.PSCredential -
  12. ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -
  13. AsPlainText -Force)
  14.  
  15. Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -
  16. Body $MailBody -SmtpServer $SmtpServer -UseSsl -Credential $Credentials -
  17. attachments "$attach"
  18.  
  19. Send-MailMessage : Could not find file
  20. 'C:UsersmyuserSystem.Net.Mail.Attachment'.
  21. At line:1 char:1
  22. + Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -
  23. Body $ ...
  24. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. + CategoryInfo : NotSpecified: (:) [Send-MailMessage],
  26. FileNotFoundException+ FullyQualifiedErrorId :
  27. System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage
Add Comment
Please, Sign In to add comment