JRA Posted April 19, 2016 Posted April 19, 2016 Hi all. I'm completely new to powershell, but recently taken over here and had to make some changes to a script that runs as a scheduled task, and which generates a password for a domain account to authenticate our public wireless against. It then email this password to a few addresses. I've tried to add a group to the list of addresses it'll email, but it's not worked. What I've done to the relevant section is in red/bold below: Function sendMail { Param( [string]$pwd ) $smtpFrom = "[email protected]" $smtpTo = "[email protected]" $smtpCC = "[email protected]", "[email protected]" $smtpBCC = "[email protected]" $smtpSubject = "Public Wifi Password for Today" $smtpBody = "The public wifi password for today is as follows`r`n`r`nUsername: public`r`nPassword: $pwd`r`n`r`nBest wishes`r`n`r`nIT Department" "auser" still gets it, but the comma and the following group do not. Anyone tell me what needs adjusting? Really really grateful for any help. Thanks.
pcstru Posted April 19, 2016 Posted April 19, 2016 I don't see where you are actually interacting with any kind of mail object. If you are using Net.Mail then adding in recipients looks like : $smtpServer = "ourmailserver.org.uk" #Creating a Mail object $msg = new-object Net.Mail.MailMessage #Creating SMTP server object $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = "[email protected]" $msg.To.Add("[email protected]") $msg.To.Add("[email protected]") $smtp.Send($msg) 1
howartp Posted April 19, 2016 Posted April 19, 2016 As PCStru says, we can't see which mail mechanism is being used. As an alternative to adding the group address to the CC recipients, is it feasible to add 'auser' into the group 'publicwifipwd' then just remove 'auser' from the $smptCC line? Peter 1
TechMonkey Posted April 19, 2016 Posted April 19, 2016 At a guess I would say the comma (or should it be a semicolon?) and the second address should all be within the first set of speech marks. When I've "played" with mail servers previously everything is text, even lists of addresses, so it is probably reading the first address and then either ignoring the second or generating an error that isn't fed back to anywhere. 1
HPlum78 Posted April 19, 2016 Posted April 19, 2016 This has been simplified in later versions of PS so it can now look like this :- $PSEmailServer = 'yourSMTPServer.yourdom.le.ac.uk' $strMailB = 'Use this to build the body of your mail' $strMailSub = 'Build the subject of your mail here' $strMailAttach = 'Path to any attachment' Send-MailMessage -To "your-GroupName <[email protected]>" -From "<[email protected]>" -Subject $strMailSub -Body $strMailB -Attachments $strMailAttch 1
JRA Posted April 19, 2016 Author Posted April 19, 2016 Thanks all for the help. I went with howartp's option in the end. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now