Solved

send mail message error

Posted on 2016-08-12
5
44 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
  • 2
  • 2
5 Comments
 
LVL 18

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 18

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 68

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now