I found some indefinite variables like ...
line 42: $server
line 43: $password and $shortDomain
The command "set-psdebug –strict" helps to find undefined variables when executing the script, just add it in the head section of your script.
Regards from Munich,
Uwe
ryanls...@gmail.com wrote:
> I am working with a script that generates a mail storm for an Exchange
> 2007 demo. Everything seems to be in place until it gets to the .send
> Here is the error I get:
>
> Exception calling "Send" with "4" argument(s): "Failure sending mail."
> At C:\Scripts\mailstorm.ps1:44 char:19
> + $smtpclient.Send( <<<< $src, $to, $title, $body)
> Found 784 mailboxes. Spamming 751 of them ...
>
> Here is the script:
>
>
> # Copyright Microsoft Corp 2006
> # written by Mihai Jalobeanu
>
> # This script reads text docs from a given location and
> # sends them as emails to all users in a given OU
>
> #include the global vars
> . .\initvars
>
> $random = new-object System.Random
>
> # read the email files from this location
> $msgs = get-item $emaildir
>
>
> # get all mailboxes
> $mbxset = get-mailbox -organizationalunit $Congress
> $mbxCount = $mbxset.Count-1 # this guarantees that the first email
> goes to everybody
> $sourceMbx = get-mailbox exadmin
>
> while (1)
> {
> if ($mbxset.Count -gt 0)
> {
>
> # pick on email
> $imsg = $random.next(0, $msgs.Count)
> $title = $msgs[$imsg].Name.Split('.')[0]
> $body = get-content $msgs[$imsg].FullName
> $Subject = "Subject"
>
> # set the sender props
> $src = $sourceMbx.PrimarySmtpAddress.ToString()
> $acct = $sourceMbx.SamAccountName
>
> # prepare the set of recipients
> $rec = 0..$mbxCount | foreach { $mbxset
> [$_].PrimarySmtpAddress.ToString() }
> $to = [string]::Join(",",$rec)
>
> # send the email
> write-host "Found $($mbxset.Count) mailboxes. Spamming $($rec.Count)
> of them ... "
> $smtpclient = new-object System.Net.Mail.SmtpClient $server, 587
$server ???
> $smtpclient.Credentials = new-object System.Net.NetworkCredential
> $acct,$password,$shortDomain
$password ???
$shortDomain ???
> $smtpclient.Send($src, $to, $title, $body)
>
>
> # pick a random number of target recipients for the next email.
> # The recipients are ordered so some of them are "preferred".
> $mbxCount = $random.Next(0,$mbxset.Count)
>
> # decide on a source mailboxfor the next email
> $sourceMbx = $mbxset[$random.next(0,$mbxset.Count/5)]
>
> }
> else
> {
> write-host "No mailboxes found..."
> start-sleep 30
> }
> }
I found some undefined variables ...
line 42: $server
line 43: $password and $shortDomain
The command "set-psdebug –strict" helps you to find undefined variables when executing the script, just add it in the head section of your script.
Regards from Munich,
Uwe
> $smtpclient.Credentials = new-object System.Net.NetworkCredential
> $acct,$password,$shortDomain