Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

send mail message error

Posted on 2016-08-12
5
Medium Priority
?
285 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 71

Accepted Solution

by:
Qlemo earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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