• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

send mail message error

every 17 messages I get an error "Send-MailMessage : Service not available, closing transmission channel. The server response was: Error: too many messages in one session"  I think it is because I have connected to the smtp server to many times and I have not disposed any of the sessions. Do you think this error is because I have not disposed the sessions?  And how would i go about disposing the sessions?


  $Fname = $_.FirstName
  $Lname = $_.LastName
  $EmpID = $_.EID
$MyEmail = "powershell@homelab.com"
$SMTP= "172.24.225.222"
$To = "administrator@homelab.com"
$Subject = "Create Email Script"
$Body = "reply 
ADD NETWORK 	$LogonName	`"$Fname`"	`"`"	`"$Lname`"	`"`"	changenow	`"Requested by:HR \r Created by:Automation`"	$EmpID	`"`"	2	`"$EmailGroup`"	`"cs staff`" 
PUT	USER	$LogonName	1252	0	$LogonName"
Start-Sleep 2
Send-MailMessage -To $to -From $MyEmail -Subject $Subject -Body $Body -SmtpServer $SMTP -Port 25 -DeliveryNotificationOption never 

Open in new window

0
Roccat
Asked:
Roccat
  • 2
  • 2
1 Solution
 
Raheman M. AbdulCommented:
logon to your smtp server 172.24.225.222  and open IIS manager, close  current sessions and then try again
Try to increase the "limit to no of connections"
do you have any open powershell sessions? close if any left

check the smtp properties in IIS manager, -> Messages > check or increase the counts
0
 
RoccatAuthor Commented:
Thanks. The other admin white listed the email address we are using to send the emails and this seems to have stopped the error message from popping up. But I still have concerns that I am leaving connections open every time I send an email.
0
 
Raheman M. AbdulCommented:
You should use the dispose() to close any open sessions :

$SMTPClient = new-object system.net.mail.smtpclient
$MailMessage = new-object system.net.mail.mailmessage

$SMTPClient.Host = $SMTPHost
$MailMessage.From = $Sender
$MailMessage.To.Add($Recipients)
$MailMessage.Subject = "TEXT HERE"
$MailMessage.Body = "BODY TEXT HERE"

$SMTPClient.Send($MailMessage)
$MailMessage.Dispose()
0
 
QlemoC++ DeveloperCommented:
Utter nonsense. Send-MailMessage does not leave a session open, and is equivalent to the manual .NET calls made in the prior comment (which again is an old-fashioned way to send mails).
The reason you get the SMTP reject message is because unknown senders (SMTP senders not being whitelisted, do not use authentication or having inproper Reverse DNS info) are restricted in the amount of messages they can send within a certain time period, to protect from using as a mail relay for SPAM unnoticed. Any means that defines the SMTP source as trustworthy removes that restriction.
1
 
RoccatAuthor Commented:
Thank you
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now