i am new to powershell scripting and i am trying to write a script that will send an email with an attachment to it. Please help
here is the code
#Clear Screen
cls Write-Host "Sending Email"
#SMTP server name
$smtpServer = "smtp.mail.yahoo.com"
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Email structure
$msg.From = "awyyyy@yahoo.com"
$msg.To.Add("yyyyyyyyy@gmail.com")
$msg.subject = "hellow"
$msg.body = "The Body of the email."
$msg.attachment = ""C:\user\user.docx""
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.EnableSsl = 1
$smtp.Port = 587
$cred = New-Object Net.NetworkCredential("sssssss@yahoo.com","xxxxxxxxxx")
$attach = New-Object Net.Mail.Attachment($msg.attachment, "C:\user\user.docx")
$msg.Attachments.Add($attach)
$smtp.Credentials = $cred
#Sending email
$smtp.Send($msg)
Write-Host "Mail Sent"