Solved

send mail message error

Posted on 2016-08-12
5
168 Views
Last Modified: 2016-08-15
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
Comment
Question by:Roccat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 41754275
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
 

Author Comment

by:Roccat
ID: 41754280
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
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 41754286
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
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 41755606
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
 

Author Closing Comment

by:Roccat
ID: 41756265
Thank you
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question