Logout

Alt-N Discussion Groups > MDaemon Discussion Groups > MDaemon Support > Archive > Problem receiving mails from powershell scripts

 [F] Alt-N Discussion Groups  / MDaemon Discussion Groups  / MDaemon Support  / Archive  /

Problem receiving mails from powershell scripts

[Cuellar, Ayuntamiento de]
Ayuntamiento de…
Novice
Novice
Posts: 122
Ayuntamiento de Cuellar - 07:08pm, Dec 6 2021

Hello

I use the powershell command "Send-MailMessage" to send emails from scripts to Mdaemon server v21.5.0.

The command are executed without problem, but the mails aren't be received in the receivers accounts.

In the Mdaemon server the SMTP-In log shows the next error in the log of the smtp sessions:

Socket error sending response to DATA * Socket error 10054 - ¡La conexión ha sido restablecida por otro lado!

The session log looks like this:
02: [01151779] <-- MAIL FROM:<sender@domain.com>
03: [01151779] --> 250 2.1.0 Sender OK
02: [01151779] <-- RCPT TO:<receiver@domain.com>
03: [01151779] --> 250 2.1.5 Recipient OK
02: [01151779] <-- DATA 03: [01151779] --> 354 Enter mail, end with <CRLF>.<CRLF>
01: [01151779] Message size: 3442 bytes
04: [01151779] Socket error sending response to DATA
04: [01151779] * Socket error 10054 - ¡La conexión ha sido restablecida por otro lado!
04: [01151779] SMTP session terminated (Bytes in/out: 3544/392)

I'm suppose the problem is in the call of "Send-MailMessage" powershell command, because the smtp-in works fine with any other e-mail client or scripts from linux machines.

How I can use the command "Send-MailMessage" to avoid that problem?

Thanks

Jorge

  All MessagesOldest ItemsOlder ItemsNewer ItemsNewest Items

Arron Caruth - Dec 8, 2021 9:48 am (#1 Total: 4)  

Guest User  

Photo of Author
Posts: 1
Can you post the full command that you are using?

Is the PowerShell script running on the MDaemon server or a different server?

I tested Send-MailMessage running on the same machine as MDaemon as well as running on a different machine and was not able to reproduce any issues.

If you add a delay after sending the email, does it help?  Something like 

sleep -Seconds 2

I usually use a function like this one when I need to send an email from a script.  The 2 second delay was only needed when sending an email was the last thing the script did.  

function SendEmail ($From, $To, $Subject,$Body){
$SMTPServer = "127.0.0.1"
$SMTPUser = "user@domain.com"
$SMTPPass = "Password1"
$SMTPMessage = new-object System.Net.Mail.MailMessage
$SMTPMessage.From = $From
$SMTPMessage.To.Add($To)
$SMTPMessage.IsBodyHtml = $True
$SMTPMessage.Subject = $Subject
$SMTPMessage.Body = $Body
$SMTPMessage.ReplyTo = "user@domain.com"

$SMTP = new-object System.Net.Mail.SmtpClient($SMTPserver, 25)
$SMTP.EnableSsl = $true
$SMTP.Credentials = New-Object System.Net.NetworkCredential($SMTPUser, $SMTPPass)
$SMTP.Send($SMTPMessage)

$SMTPMessage.Dispose()
sleep -Seconds 2

}

--
Arron Caruth
Vice President of Product Development
o: 817-601-3222    e: Arron.Caruth@mdaemon.com

MDaemon Technologies
Simple Secure Email

Visit us on www.mdaemon.com | Facebook | LinkedIn | YouTube
Sent using the MDaemon Email Server

On Mon, 6 Dec 2021 19:08:29 -0500, "lists-md-support@mdaemon.com (Ayuntamiento de Cuellar)" <lists-md-support@mdaemon.com> wrote:
Hello

I use the powershell command "Send-MailMessage" to send emails from scripts to Mdaemon server v21.5.0.

The command are executed without problem, but the mails aren't be received in the receivers accounts.

In the Mdaemon server the SMTP-In log shows the next error in the log of the smtp sessions:

Socket error sending response to DATA * Socket error 10054 - A!La conexiA3n ha sido restablecida por otro lado!

The session log looks like this:
02: [01151779] <-- MAIL FROM:<sender@domain.com>
03: [01151779] --> 250 2.1.0 Sender OK
02: [01151779] <-- RCPT TO:<receiver@domain.com>
03: [01151779] --> 250 2.1.5 Recipient OK
02: [01151779] <-- DATA 03: [01151779] --> 354 Enter mail, end with <CRLF>.<CRLF>
01: [01151779] Message size: 3442 bytes
04: [01151779] Socket error sending response to DATA
04: [01151779] * Socket error 10054 - A!La conexiA3n ha sido restablecida por otro lado!
04: [01151779] SMTP session terminated (Bytes in/out: 3544/392)

I'm suppose the problem is in the call of "Send-MailMessage" powershell command, because the smtp-in works fine with any other e-mail client or scripts from linux machines.

How I can use the command "Send-MailMessage" to avoid that problem?

Thanks

Jorge


View/reply at Problem receiving mails from powershell scripts
--MD-SUPPORT--------------------------------------------------------------
This list is for questions and discussion about MDAEMON. To unsubscribe 
from this mailing list send an email to md-support-unsubscribe@mdaemon.com .
--POWERED BY MDAEMON!-----------------------------------------------------

--------------------------------------------------------------------------
These forums are provided by MDaemon Technologies for user-to-user 
support and discussion.  MDaemon staff members may participate in the 
forums periodically but please recognize that this is not the official
method of receiving technical support. To receive personal technical 
support please use the form here:
http://www.mdaemon.com/Support/RequestSupport/
--------------------------------------------------------------------------

--MD-SUPPORT--------------------------------------------------------------
This list is for questions and discussion about MDAEMON. To unsubscribe 
from this mailing list send an email to md-support-unsubscribe@mdaemon.com .
--POWERED BY MDAEMON!-----------------------------------------------------

--------------------------------------------------------------------------
These forums are provided by MDaemon Technologies for user-to-user 
support and discussion.  MDaemon staff members may participate in the 
forums periodically but please recognize that this is not the official
method of receiving technical support. To receive personal technical 
support please use the form here:
http://www.mdaemon.com/Support/RequestSupport/
--------------------------------------------------------------------------



  (newer msg:3)All MessagesOldest ItemsOlder ItemsNewer ItemsNewest Items



 Content:

Read New | Search

 Guest:

Email to Admin



You are visiting as a Guest user.