For a script i want to send an email with a attachement to different kind of users.
I already have the following:
$Sender = $emailaddress
$SMTP = "outlook.office365.com"
$Recipients = @("[firstname Lastname] ", "[firstname Lastname] ", "[firstname Lastname] ")
$Subject = $Emailsubject
$Body = $EmailMessage
$Attachment = new-object Net.Mail.Attachment($fileLocation)
Is it possible for recipient box i can create the smae i have for the $emailaddress
that is:
$Emailaddress = [microsoft.visualbasic.interaction]::inputbox('give up Email address','Emailaddress','...@campofriofg.com')
But then that it is possible to imput multiple emailddresses ?
Would it perhaps be best to add in the description that users need to comma separate the email addresses? Then use a foreach loop to send the emails?
eg.
$EmailAddresses = $([microsoft.visualbasic.interaction]::inputbox('Provide email addresses, separated by commas','Emailaddress','...@campofriofg.com')).Split(",")
foreach ($EmailAddress in $EmailAddresses)
{
*Email sending code*
}
Edit: in fact, as per Olaf Soyk’s suggestion above, looks like Send-MailMessage would be able to accept $EmailAddresses (string array).
$EmailAddresses = $([microsoft.visualbasic.interaction]::inputbox('Provide email addresses, separated by commas','Emailaddress','...@campofriofg.com')).Split(",")
Send-MailMessage -To $EmailAddresses .... and so on.