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/
--------------------------------------------------------------------------

Ayuntamiento de Cuellar (apparently) - Dec 8, 2021 1:38 pm (#2 Total: 4)  

via email  

Photo of Author
Ayuntamiento de…
Novice
Novice
Posts: 122
Hi Arron

     The script is running in other machines different from the Mdaemon
server.

     The powershell command is embedded in a batch script:

c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe ^
        Send-MailMessage -From 'sender@domain.com' -To
'receiver@domain.com'   ^
                  -Subject ('This is the subject')          ^
                  -Body ('This is the body')     ^
                  -SmtpServer 'mdaemon.domain.com'

     I've done some tests more and I think the send-mailmessage command
doesn't close the connection correctly.

First, I added a "Test-Connection mdaemon.domain.com -count 1" command
after send-mailmessage. In this case, the mail is delivered to the
recipient and the result in the log is:

Wed 2021-12-08 17:44:11.940: 03: [01153003] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 17:44:11.942: 01: [01153003] Message size: 260 bytes
Wed 2021-12-08 17:44:12.014: 01: [01153003] Creación del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371989.msg
Wed 2021-12-08 17:44:12.014: 03: [01153003] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 17:44:12.200: 04: [01153003] *  Socket error 10054 - ¡La
conexión ha sido restablecida por otro lado!
Wed 2021-12-08 17:44:12.200: 01: [01153003] SMTP session successful
(Bytes in/out: 361/419)

Then I've deleted the "Test-Connection mdaemon.domain.com -count 1"
command and the log was:

Wed 2021-12-08 17:45:47.186: 03: [01153046] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 17:45:47.188: 01: [01153046] Message size: 260 bytes
Wed 2021-12-08 17:45:47.200: 04: [01153046] Socket error sending
response to DATA
Wed 2021-12-08 17:45:47.201: 04: [01153046] *  Socket error 10054 - ¡La
conexión ha sido restablecida por otro lado!
Wed 2021-12-08 17:45:47.201: 04: [01153046] SMTP session terminated
(Bytes in/out: 361/390)

Then I've added a "Sleep -Seconds 2" command before "Send-MailMessage"
and the log was:

Wed 2021-12-08 19:00:29.709: 03: [01153048] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 19:00:29.711: 01: [01153048] Message size: 260 bytes
Wed 2021-12-08 19:00:29.778: 01: [01153048] Creación del mensaje
successful: i:\mdaemon\queues\inbound\md5001001372004.msg
Wed 2021-12-08 19:00:29.778: 03: [01153048] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 19:00:31.728: 04: [01153048] *  Socket error 10054 - ¡La
conexión ha sido restablecida por otro lado!
Wed 2021-12-08 19:00:31.728: 01: [01153048] SMTP session successful
(Bytes in/out: 361/419)


So the error always appears, but the mail is delivered when we put a
command after the "Send-MailMessage" command.

Then I've created the next powershell script:

Send-MailMessage -From 'sender@domain.com' -To 'receiver@domain.com'
-Subject ('This is the subject') -Body ('This is the body') -SmtpServer
'mdaemon.domain.com'

I've opened a powershell console and I run the script three times with
many seconds between them. The Mdaemon log is:

Wed 2021-12-08 18:22:55.465: 05: [01153031] Session 01153031; child 0001
Wed 2021-12-08 18:22:55.465: 05: [01153031] Accepting SMTP connection
from XXX.XXX.XXX.XXX:51944 to YYY.YYY.YYY.YYY:25
Wed 2021-12-08 18:22:55.467: 03: [01153031] --> 220 mdaemon.domain.com
ESMTP Wed, 08 Dec 2021 18:22:55 +0100
Wed 2021-12-08 18:22:55.468: 02: [01153031] <-- EHLO Machine
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-mdaemon.domain.com
Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-VRFY
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-EXPN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-ETRN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-AUTH LOGIN CRAM-MD5
PLAIN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-8BITMIME
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-ENHANCEDSTATUSCODES
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-PIPELINING
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-CHUNKING
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-STARTTLS
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250 SIZE 51200000
Wed 2021-12-08 18:22:55.470: 02: [01153031] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:22:55.470: 03: [01153031] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:22:55.471: 02: [01153031] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:22:55.472: 03: [01153031] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:22:55.473: 02: [01153031] <-- DATA
Wed 2021-12-08 18:22:55.475: 03: [01153031] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:22:55.476: 01: [01153031] Message size: 260 bytes
Wed 2021-12-08 18:22:55.533: 01: [01153031] Creación del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371996.msg
Wed 2021-12-08 18:22:55.533: 03: [01153031] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:23:45.175: 02: [01153031] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:23:45.175: 03: [01153031] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:23:45.176: 02: [01153031] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:23:45.176: 03: [01153031] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:23:45.177: 02: [01153031] <-- DATA
Wed 2021-12-08 18:23:45.180: 03: [01153031] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:23:45.181: 01: [01153031] Message size: 260 bytes
Wed 2021-12-08 18:23:45.232: 01: [01153031] Creación del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371997.msg
Wed 2021-12-08 18:23:45.232: 03: [01153031] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:24:35.486: 02: [01153031] <-- QUIT
Wed 2021-12-08 18:24:35.486: 03: [01153031] --> 221 2.0.0 See ya in
cyberspace
Wed 2021-12-08 18:24:35.486: 01: [01153031] SMTP session successful
(Bytes in/out: 714/565)
Wed 2021-12-08 18:24:35.486: 01: ----------
Wed 2021-12-08 18:24:51.661: 05: [01153032] Session 01153032; child 0001
Wed 2021-12-08 18:24:51.661: 05: [01153032] Accepting SMTP connection
from XXX.XXX.XXX.XXX:51945 to YYY.YYY.YYY.YYY:25
Wed 2021-12-08 18:24:51.664: 03: [01153032] --> 220 mdaemon.domain.com
ESMTP Wed, 08 Dec 2021 18:24:51 +0100
Wed 2021-12-08 18:24:51.666: 02: [01153032] <-- EHLO Machine
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-mdaemon.domain.com
Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-VRFY
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-EXPN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-ETRN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-AUTH LOGIN CRAM-MD5
PLAIN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-8BITMIME
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-ENHANCEDSTATUSCODES
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-PIPELINING
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-CHUNKING
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-STARTTLS
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250 SIZE 51200000
Wed 2021-12-08 18:24:51.667: 02: [01153032] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:24:51.667: 03: [01153032] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:24:51.669: 02: [01153032] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:24:51.669: 03: [01153032] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:24:51.670: 02: [01153032] <-- DATA
Wed 2021-12-08 18:24:51.672: 03: [01153032] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:24:51.674: 01: [01153032] Message size: 260 bytes
Wed 2021-12-08 18:24:51.730: 01: [01153032] Creación del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371998.msg
Wed 2021-12-08 18:24:51.730: 03: [01153032] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:26:15.518: 02: [01153032] <-- QUIT
Wed 2021-12-08 18:26:15.518: 03: [01153032] --> 221 2.0.0 See ya in
cyberspace
Wed 2021-12-08 18:26:15.518: 01: [01153032] SMTP session successful
(Bytes in/out: 367/451)
Wed 2021-12-08 18:26:15.519: 01: ----------


     Each time the script is run, in Mdaemon there should be a different
session, but it looks like continue the previous session for the second
running of the script. Also if you see the times from commands "250
2.6.0 Ok, message saved" to the next commands, Mdaemon looks like close
the session by a timeout of about 80 seconds. The powershell console was
opened all time during this tests.

     Finally, I've tested your function and the results are similar to
mine:
   * when the script is running out of powershell console, the message
is delivered, but the "socket error 10054" appears in the log.
   * when the script is running in a powershell console, the message is
delivered, the socket error doesn't appear, but the log show the session
is closed about 80 seconds later.

     I suppose when send-mailmessage or "$SMTP.Send($SMTPMessage)" are
the last command of the script, the session is closed too early when the
script finish and Mdaemon doesn't save the mail, but if the script
finish a few time later, Mdaemon has been able to save the message and
it can be delivered, although the connection is still closed abruptly.

     Have you got the same behaviour?

     Thanks

--

Jorge

El 8/12/21 a las 15:48, Arron Caruth (Arron.Caruth@mdaemon.com) escribió:

> 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
>
> *M*Daemon Technologies
> Simple Secure Email
>
> Visit us on www.mdaemon.com <www.mdaemon.com> | Facebook
> <https://www.facebook.com/MDaemon.Technologies/> | LinkedIn
> <https://www.linkedin.com/company/mdaemon-technologies> | YouTube
> <https://www.youtube.com/c/MDaemonTechnologies>
> Sent using the MDaemon Email Server <http://www.mdaemon.com/>
>
> 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
> <http://lists.altn.com/WebX?13@@.59863cf5>
>
> --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/
> --------------------------------------------------------------------------



--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/
--------------------------------------------------------------------------



Arron Caruth - Dec 8, 2021 3:30 pm (#3 Total: 4)  

Guest User  

Photo of Author
Posts: 1
Yes, in many cases I found that adding a delay after sending the message would allow the email to send correctly.  


--
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 Wed, 8 Dec 2021 19:38:36 +0100, "informatica@aytocuellar.es (Jorge Redondo)" <informatica@aytocuellar.es> wrote:
Hi Arron

     The script is running in other machines different from the Mdaemon
server.

     The powershell command is embedded in a batch script:

c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe ^
        Send-MailMessage -From 'sender@domain.com' -To
'receiver@domain.com'   ^
                  -Subject ('This is the subject')          ^
                  -Body ('This is the body')     ^
                  -SmtpServer 'mdaemon.domain.com'

     I've done some tests more and I think the send-mailmessage command
doesn't close the connection correctly.

First, I added a "Test-Connection mdaemon.domain.com -count 1" command
after send-mailmessage. In this case, the mail is delivered to the
recipient and the result in the log is:

Wed 2021-12-08 17:44:11.940: 03: [01153003] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 17:44:11.942: 01: [01153003] Message size: 260 bytes
Wed 2021-12-08 17:44:12.014: 01: [01153003] Creacin del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371989.msg
Wed 2021-12-08 17:44:12.014: 03: [01153003] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 17:44:12.200: 04: [01153003] *  Socket error 10054 - La
conexin ha sido restablecida por otro lado!
Wed 2021-12-08 17:44:12.200: 01: [01153003] SMTP session successful
(Bytes in/out: 361/419)

Then I've deleted the "Test-Connection mdaemon.domain.com -count 1"
command and the log was:

Wed 2021-12-08 17:45:47.186: 03: [01153046] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 17:45:47.188: 01: [01153046] Message size: 260 bytes
Wed 2021-12-08 17:45:47.200: 04: [01153046] Socket error sending
response to DATA
Wed 2021-12-08 17:45:47.201: 04: [01153046] *  Socket error 10054 - La
conexin ha sido restablecida por otro lado!
Wed 2021-12-08 17:45:47.201: 04: [01153046] SMTP session terminated
(Bytes in/out: 361/390)

Then I've added a "Sleep -Seconds 2" command before "Send-MailMessage"
and the log was:

Wed 2021-12-08 19:00:29.709: 03: [01153048] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 19:00:29.711: 01: [01153048] Message size: 260 bytes
Wed 2021-12-08 19:00:29.778: 01: [01153048] Creacin del mensaje
successful: i:\mdaemon\queues\inbound\md5001001372004.msg
Wed 2021-12-08 19:00:29.778: 03: [01153048] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 19:00:31.728: 04: [01153048] *  Socket error 10054 - La
conexin ha sido restablecida por otro lado!
Wed 2021-12-08 19:00:31.728: 01: [01153048] SMTP session successful
(Bytes in/out: 361/419)


So the error always appears, but the mail is delivered when we put a
command after the "Send-MailMessage" command.

Then I've created the next powershell script:

Send-MailMessage -From 'sender@domain.com' -To 'receiver@domain.com'
-Subject ('This is the subject') -Body ('This is the body') -SmtpServer
'mdaemon.domain.com'

I've opened a powershell console and I run the script three times with
many seconds between them. The Mdaemon log is:

Wed 2021-12-08 18:22:55.465: 05: [01153031] Session 01153031; child 0001
Wed 2021-12-08 18:22:55.465: 05: [01153031] Accepting SMTP connection
from XXX.XXX.XXX.XXX:51944 to YYY.YYY.YYY.YYY:25
Wed 2021-12-08 18:22:55.467: 03: [01153031] --> 220 mdaemon.domain.com
ESMTP Wed, 08 Dec 2021 18:22:55 +0100
Wed 2021-12-08 18:22:55.468: 02: [01153031] <-- EHLO Machine
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-mdaemon.domain.com
Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-VRFY
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-EXPN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-ETRN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-AUTH LOGIN CRAM-MD5
PLAIN
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-8BITMIME
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-ENHANCEDSTATUSCODES
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-PIPELINING
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-CHUNKING
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-STARTTLS
Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250 SIZE 51200000
Wed 2021-12-08 18:22:55.470: 02: [01153031] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:22:55.470: 03: [01153031] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:22:55.471: 02: [01153031] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:22:55.472: 03: [01153031] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:22:55.473: 02: [01153031] <-- DATA
Wed 2021-12-08 18:22:55.475: 03: [01153031] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:22:55.476: 01: [01153031] Message size: 260 bytes
Wed 2021-12-08 18:22:55.533: 01: [01153031] Creacin del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371996.msg
Wed 2021-12-08 18:22:55.533: 03: [01153031] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:23:45.175: 02: [01153031] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:23:45.175: 03: [01153031] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:23:45.176: 02: [01153031] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:23:45.176: 03: [01153031] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:23:45.177: 02: [01153031] <-- DATA
Wed 2021-12-08 18:23:45.180: 03: [01153031] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:23:45.181: 01: [01153031] Message size: 260 bytes
Wed 2021-12-08 18:23:45.232: 01: [01153031] Creacin del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371997.msg
Wed 2021-12-08 18:23:45.232: 03: [01153031] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:24:35.486: 02: [01153031] <-- QUIT
Wed 2021-12-08 18:24:35.486: 03: [01153031] --> 221 2.0.0 See ya in
cyberspace
Wed 2021-12-08 18:24:35.486: 01: [01153031] SMTP session successful
(Bytes in/out: 714/565)
Wed 2021-12-08 18:24:35.486: 01: ----------
Wed 2021-12-08 18:24:51.661: 05: [01153032] Session 01153032; child 0001
Wed 2021-12-08 18:24:51.661: 05: [01153032] Accepting SMTP connection
from XXX.XXX.XXX.XXX:51945 to YYY.YYY.YYY.YYY:25
Wed 2021-12-08 18:24:51.664: 03: [01153032] --> 220 mdaemon.domain.com
ESMTP Wed, 08 Dec 2021 18:24:51 +0100
Wed 2021-12-08 18:24:51.666: 02: [01153032] <-- EHLO Machine
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-mdaemon.domain.com
Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-VRFY
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-EXPN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-ETRN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-AUTH LOGIN CRAM-MD5
PLAIN
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-8BITMIME
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-ENHANCEDSTATUSCODES
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-PIPELINING
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-CHUNKING
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-STARTTLS
Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250 SIZE 51200000
Wed 2021-12-08 18:24:51.667: 02: [01153032] <-- MAIL
FROM:<sender@domain.com>
Wed 2021-12-08 18:24:51.667: 03: [01153032] --> 250 2.1.0 Sender OK
Wed 2021-12-08 18:24:51.669: 02: [01153032] <-- RCPT
TO:<receiver@domain.com>
Wed 2021-12-08 18:24:51.669: 03: [01153032] --> 250 2.1.5 Recipient OK
Wed 2021-12-08 18:24:51.670: 02: [01153032] <-- DATA
Wed 2021-12-08 18:24:51.672: 03: [01153032] --> 354 Enter mail, end with
<CRLF>.<CRLF>
Wed 2021-12-08 18:24:51.674: 01: [01153032] Message size: 260 bytes
Wed 2021-12-08 18:24:51.730: 01: [01153032] Creacin del mensaje
successful: c:\mdaemon\queues\inbound\md5001001371998.msg
Wed 2021-12-08 18:24:51.730: 03: [01153032] --> 250 2.6.0 Ok, message saved
Wed 2021-12-08 18:26:15.518: 02: [01153032] <-- QUIT
Wed 2021-12-08 18:26:15.518: 03: [01153032] --> 221 2.0.0 See ya in
cyberspace
Wed 2021-12-08 18:26:15.518: 01: [01153032] SMTP session successful
(Bytes in/out: 367/451)
Wed 2021-12-08 18:26:15.519: 01: ----------


     Each time the script is run, in Mdaemon there should be a different
session, but it looks like continue the previous session for the second
running of the script. Also if you see the times from commands "250
2.6.0 Ok, message saved" to the next commands, Mdaemon looks like close
the session by a timeout of about 80 seconds. The powershell console was
opened all time during this tests.

     Finally, I've tested your function and the results are similar to
mine:
   * when the script is running out of powershell console, the message
is delivered, but the "socket error 10054" appears in the log.
   * when the script is running in a powershell console, the message is
delivered, the socket error doesn't appear, but the log show the session
is closed about 80 seconds later.

     I suppose when send-mailmessage or "$SMTP.Send($SMTPMessage)" are
the last command of the script, the session is closed too early when the
script finish and Mdaemon doesn't save the mail, but if the script
finish a few time later, Mdaemon has been able to save the message and
it can be delivered, although the connection is still closed abruptly.

     Have you got the same behaviour?

     Thanks

--

Jorge

El 8/12/21 a las 15:48, Arron Caruth (Arron.Caruth@mdaemon.com) escribi:

> 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
>
> *M*Daemon Technologies
> Simple Secure Email
>
> Visit us on www.mdaemon.com <www.mdaemon.com> | Facebook
> <https://www.facebook.com/MDaemon.Technologies/> | LinkedIn
> <https://www.linkedin.com/company/mdaemon-technologies> | YouTube
> <https://www.youtube.com/c/MDaemonTechnologies>
> Sent using the MDaemon Email Server <http://www.mdaemon.com/>
>
>     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
>     <http://lists.altn.com/WebX?13@@.59863cf5>
>
>     --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/
> --------------------------------------------------------------------------



--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/
--------------------------------------------------------------------------

Ayuntamiento de Cuellar (apparently) - Dec 8, 2021 5:31 pm (#4 Total: 4)  

via email  

Photo of Author
Ayuntamiento de…
Novice
Novice
Posts: 122
Ok, Arron

Thank you very much

Best regards

--

Jorge


El 8/12/21 a las 21:30, Arron Caruth (Arron.Caruth@mdaemon.com) escribió:

> Yes, in many cases I found that adding a delay after sending the
> message would allow the email to send correctly.
>
>
> --
> *Arron Caruth*
> Vice President of Product Development
> *o*: 817-601-3222 *e*: Arron.Caruth@mdaemon.com
>
> *M*Daemon Technologies
> Simple Secure Email
>
> Visit us on www.mdaemon.com <www.mdaemon.com> | Facebook
> <https://www.facebook.com/MDaemon.Technologies/> | LinkedIn
> <https://www.linkedin.com/company/mdaemon-technologies> | YouTube
> <https://www.youtube.com/c/MDaemonTechnologies>
> Sent using the MDaemon Email Server <http://www.mdaemon.com/>
>
> On Wed, 8 Dec 2021 19:38:36 +0100, "informatica@aytocuellar.es
> (Jorge Redondo)" <informatica@aytocuellar.es> wrote:
> Hi Arron
>
>      The script is running in other machines different from the
> Mdaemon
> server.
>
>      The powershell command is embedded in a batch script:
>
> c:\windows\System32\WindowsPowerShell\v1.0\powershell.exe ^
>         Send-MailMessage -From 'sender@domain.com
> <mailto:sender%40domain.com>' -To
> 'receiver@domain.com <mailto:receiver%40domain.com>' ^
>                   -Subject ('This is the subject')          ^
>                   -Body ('This is the body')     ^
>                   -SmtpServer 'mdaemon.domain.com'
>
>      I've done some tests more and I think the send-mailmessage
> command
> doesn't close the connection correctly.
>
> First, I added a "Test-Connection mdaemon.domain.com -count 1"
> command
> after send-mailmessage. In this case, the mail is delivered to the
> recipient and the result in the log is:
>
> Wed 2021-12-08 17:44:11.940: 03: [01153003] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 17:44:11.942: 01: [01153003] Message size: 260 bytes
> Wed 2021-12-08 17:44:12.014: 01: [01153003] Creación del mensaje
> successful: c:\mdaemon\queues\inbound\md5001001371989.msg
> Wed 2021-12-08 17:44:12.014: 03: [01153003] --> 250 2.6.0 Ok,
> message saved
> Wed 2021-12-08 17:44:12.200: 04: [01153003] *  Socket error 10054
> - ¡La
> conexión ha sido restablecida por otro lado!
> Wed 2021-12-08 17:44:12.200: 01: [01153003] SMTP session successful
> (Bytes in/out: 361/419)
>
> Then I've deleted the "Test-Connection mdaemon.domain.com -count 1"
> command and the log was:
>
> Wed 2021-12-08 17:45:47.186: 03: [01153046] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 17:45:47.188: 01: [01153046] Message size: 260 bytes
> Wed 2021-12-08 17:45:47.200: 04: [01153046] Socket error sending
> response to DATA
> Wed 2021-12-08 17:45:47.201: 04: [01153046] *  Socket error 10054
> - ¡La
> conexión ha sido restablecida por otro lado!
> Wed 2021-12-08 17:45:47.201: 04: [01153046] SMTP session terminated
> (Bytes in/out: 361/390)
>
> Then I've added a "Sleep -Seconds 2" command before
> "Send-MailMessage"
> and the log was:
>
> Wed 2021-12-08 19:00:29.709: 03: [01153048] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 19:00:29.711: 01: [01153048] Message size: 260 bytes
> Wed 2021-12-08 19:00:29.778: 01: [01153048] Creación del mensaje
> successful: i:\mdaemon\queues\inbound\md5001001372004.msg
> Wed 2021-12-08 19:00:29.778: 03: [01153048] --> 250 2.6.0 Ok,
> message saved
> Wed 2021-12-08 19:00:31.728: 04: [01153048] *  Socket error 10054
> - ¡La
> conexión ha sido restablecida por otro lado!
> Wed 2021-12-08 19:00:31.728: 01: [01153048] SMTP session successful
> (Bytes in/out: 361/419)
>
>
> So the error always appears, but the mail is delivered when we put a
> command after the "Send-MailMessage" command.
>
> Then I've created the next powershell script:
>
> Send-MailMessage -From 'sender@domain.com
> <mailto:sender%40domain.com>' -To 'receiver@domain.com
> <mailto:receiver%40domain.com>'
> -Subject ('This is the subject') -Body ('This is the body')
> -SmtpServer
> 'mdaemon.domain.com'
>
> I've opened a powershell console and I run the script three times
> with
> many seconds between them. The Mdaemon log is:
>
> Wed 2021-12-08 18:22:55.465: 05: [01153031] Session 01153031;
> child 0001
> Wed 2021-12-08 18:22:55.465: 05: [01153031] Accepting SMTP connection
> from XXX.XXX.XXX.XXX:51944 to YYY.YYY.YYY.YYY:25
> Wed 2021-12-08 18:22:55.467: 03: [01153031] --> 220
> mdaemon.domain.com
> ESMTP Wed, 08 Dec 2021 18:22:55 +0100
> Wed 2021-12-08 18:22:55.468: 02: [01153031] <-- EHLO Machine
> Wed 2021-12-08 18:22:55.468: 03: [01153031] -->
> 250-mdaemon.domain.com
> Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-VRFY
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-EXPN
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-ETRN
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-AUTH LOGIN
> CRAM-MD5
> PLAIN
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-8BITMIME
> Wed 2021-12-08 18:22:55.468: 03: [01153031] -->
> 250-ENHANCEDSTATUSCODES
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-PIPELINING
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-CHUNKING
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250-STARTTLS
> Wed 2021-12-08 18:22:55.468: 03: [01153031] --> 250 SIZE 51200000
> Wed 2021-12-08 18:22:55.470: 02: [01153031] <-- MAIL
> FROM:<sender@domain.com <mailto:sender%40domain.com>>
> Wed 2021-12-08 18:22:55.470: 03: [01153031] --> 250 2.1.0 Sender OK
> Wed 2021-12-08 18:22:55.471: 02: [01153031] <-- RCPT
> TO:<receiver@domain.com <mailto:receiver%40domain.com>>
> Wed 2021-12-08 18:22:55.472: 03: [01153031] --> 250 2.1.5 Recipient OK
> Wed 2021-12-08 18:22:55.473: 02: [01153031] <-- DATA
> Wed 2021-12-08 18:22:55.475: 03: [01153031] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 18:22:55.476: 01: [01153031] Message size: 260 bytes
> Wed 2021-12-08 18:22:55.533: 01: [01153031] Creación del mensaje
> successful: c:\mdaemon\queues\inbound\md5001001371996.msg
> Wed 2021-12-08 18:22:55.533: 03: [01153031] --> 250 2.6.0 Ok,
> message saved
> Wed 2021-12-08 18:23:45.175: 02: [01153031] <-- MAIL
> FROM:<sender@domain.com <mailto:sender%40domain.com>>
> Wed 2021-12-08 18:23:45.175: 03: [01153031] --> 250 2.1.0 Sender OK
> Wed 2021-12-08 18:23:45.176: 02: [01153031] <-- RCPT
> TO:<receiver@domain.com <mailto:receiver%40domain.com>>
> Wed 2021-12-08 18:23:45.176: 03: [01153031] --> 250 2.1.5 Recipient OK
> Wed 2021-12-08 18:23:45.177: 02: [01153031] <-- DATA
> Wed 2021-12-08 18:23:45.180: 03: [01153031] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 18:23:45.181: 01: [01153031] Message size: 260 bytes
> Wed 2021-12-08 18:23:45.232: 01: [01153031] Creación del mensaje
> successful: c:\mdaemon\queues\inbound\md5001001371997.msg
> Wed 2021-12-08 18:23:45.232: 03: [01153031] --> 250 2.6.0 Ok,
> message saved
> Wed 2021-12-08 18:24:35.486: 02: [01153031] <-- QUIT
> Wed 2021-12-08 18:24:35.486: 03: [01153031] --> 221 2.0.0 See ya in
> cyberspace
> Wed 2021-12-08 18:24:35.486: 01: [01153031] SMTP session successful
> (Bytes in/out: 714/565)
> Wed 2021-12-08 18:24:35.486: 01: ----------
> Wed 2021-12-08 18:24:51.661: 05: [01153032] Session 01153032;
> child 0001
> Wed 2021-12-08 18:24:51.661: 05: [01153032] Accepting SMTP connection
> from XXX.XXX.XXX.XXX:51945 to YYY.YYY.YYY.YYY:25
> Wed 2021-12-08 18:24:51.664: 03: [01153032] --> 220
> mdaemon.domain.com
> ESMTP Wed, 08 Dec 2021 18:24:51 +0100
> Wed 2021-12-08 18:24:51.666: 02: [01153032] <-- EHLO Machine
> Wed 2021-12-08 18:24:51.666: 03: [01153032] -->
> 250-mdaemon.domain.com
> Hello Machine [XXX.XXX.XXX.XXX], pleased to meet you
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-VRFY
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-EXPN
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-ETRN
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-AUTH LOGIN
> CRAM-MD5
> PLAIN
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-8BITMIME
> Wed 2021-12-08 18:24:51.666: 03: [01153032] -->
> 250-ENHANCEDSTATUSCODES
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-PIPELINING
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-CHUNKING
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250-STARTTLS
> Wed 2021-12-08 18:24:51.666: 03: [01153032] --> 250 SIZE 51200000
> Wed 2021-12-08 18:24:51.667: 02: [01153032] <-- MAIL
> FROM:<sender@domain.com <mailto:sender%40domain.com>>
> Wed 2021-12-08 18:24:51.667: 03: [01153032] --> 250 2.1.0 Sender OK
> Wed 2021-12-08 18:24:51.669: 02: [01153032] <-- RCPT
> TO:<receiver@domain.com <mailto:receiver%40domain.com>>
> Wed 2021-12-08 18:24:51.669: 03: [01153032] --> 250 2.1.5 Recipient OK
> Wed 2021-12-08 18:24:51.670: 02: [01153032] <-- DATA
> Wed 2021-12-08 18:24:51.672: 03: [01153032] --> 354 Enter mail,
> end with
> <CRLF>.<CRLF>
> Wed 2021-12-08 18:24:51.674: 01: [01153032] Message size: 260 bytes
> Wed 2021-12-08 18:24:51.730: 01: [01153032] Creación del mensaje
> successful: c:\mdaemon\queues\inbound\md5001001371998.msg
> Wed 2021-12-08 18:24:51.730: 03: [01153032] --> 250 2.6.0 Ok,
> message saved
> Wed 2021-12-08 18:26:15.518: 02: [01153032] <-- QUIT
> Wed 2021-12-08 18:26:15.518: 03: [01153032] --> 221 2.0.0 See ya in
> cyberspace
> Wed 2021-12-08 18:26:15.518: 01: [01153032] SMTP session successful
> (Bytes in/out: 367/451)
> Wed 2021-12-08 18:26:15.519: 01: ----------
>
>
>      Each time the script is run, in Mdaemon there should be a
> different
> session, but it looks like continue the previous session for the
> second
> running of the script. Also if you see the times from commands "250
> 2.6.0 Ok, message saved" to the next commands, Mdaemon looks like
> close
> the session by a timeout of about 80 seconds. The powershell
> console was
> opened all time during this tests.
>
>      Finally, I've tested your function and the results are
> similar to
> mine:
>    * when the script is running out of powershell console, the
> message
> is delivered, but the "socket error 10054" appears in the log.
>    * when the script is running in a powershell console, the
> message is
> delivered, the socket error doesn't appear, but the log show the
> session
> is closed about 80 seconds later.
>
>      I suppose when send-mailmessage or "$SMTP.Send($SMTPMessage)"
> are
> the last command of the script, the session is closed too early
> when the
> script finish and Mdaemon doesn't save the mail, but if the script
> finish a few time later, Mdaemon has been able to save the message
> and
> it can be delivered, although the connection is still closed abruptly.
>
>      Have you got the same behaviour?
>
>      Thanks
>
> --
>
> Jorge
>
> El 8/12/21 a las 15:48, Arron Caruth (Arron.Caruth@mdaemon.com
> <mailto:Arron.Caruth%40mdaemon.com>) escribió:
>
> > 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 <mailto:user%40domain.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 <mailto:user%40domain.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
> <mailto:Arron.Caruth%40mdaemon.com>
> >
> > *M*Daemon Technologies
> > Simple Secure Email
> >
> > Visit us on www.mdaemon.com <http://www.mdaemon.com>
> <www.mdaemon.com <http://www.mdaemon.com>> | Facebook
> > <https://www.facebook.com/MDaemon.Technologies/
> <https://www.facebook.com/MDaemon.Technologies/>> | LinkedIn
> > <https://www.linkedin.com/company/mdaemon-technologies
> <https://www.linkedin.com/company/mdaemon-technologies>> | YouTube
> > <https://www.youtube.com/c/MDaemonTechnologies
> <https://www.youtube.com/c/MDaemonTechnologies>>
> > Sent using the MDaemon Email Server <http://www.mdaemon.com/
> <http://www.mdaemon.com/>>
> >
> >     On Mon, 6 Dec 2021 19:08:29 -0500,
> "lists-md-support@mdaemon.com <mailto:lists-md-support%40mdaemon.com>
> >     (Ayuntamiento de Cuellar)" <lists-md-support@mdaemon.com
> <mailto:lists-md-support%40mdaemon.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
> <mailto:sender%40domain.com>>
> >     03: [01151779] --> 250 2.1.0 Sender OK
> >     02: [01151779] <-- RCPT TO:<receiver@domain.com
> <mailto:receiver%40domain.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
> >     <http://lists.altn.com/WebX?13@@.59863cf5
> <http://lists.altn.com/WebX?13@@.59863cf5>>
> >
> >
> --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
> <mailto:md-support-unsubscribe%40mdaemon.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/
> <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
> <mailto:md-support-unsubscribe%40mdaemon.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/
> <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
> <mailto:md-support-unsubscribe%40mdaemon.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/
> <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/
> --------------------------------------------------------------------------



--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/
--------------------------------------------------------------------------





  All MessagesOldest ItemsOlder ItemsNewer ItemsNewest Items



 Content:

Read New | Search

 Guest:

Email to Admin



You are visiting as a Guest user.