function SendSmtpMail($server, $sender, $recipients, $subject, $body, $file){ $msg = new-object Net.Mail.MailMessage $smtpServer = new-object Net.Mail.SmtpClient($server) $msg.From = $sender $msg.Subject = $subject $msg.Body = $body foreach ($recipient in $recipients) { $msg.To.Add($recipient) } if ($file -ne "") { $att = new-object Net.Mail.Attachment($file) $msg.Attachments.Add($att) } $smtpServer.Send($msg) if ($file -ne "") { $att.Dispose() }}$smtpServer = "my smtp server"$file = "path to file"$recipients = @( "user1@test.de", "user2@test.de" )$sender = "sender@mydomain.com"$subject = "My Subject"$body = "My Mail Text"SendSmtpMail $smtpServer $sender $recipients $subject $body $file