From 60e3e79500fe133ea4914cb36336630c59fe2c05 Mon Sep 17 00:00:00 2001 From: gambas Date: Fri, 6 Dec 2019 21:22:28 +0100 Subject: [PATCH] Make SmtpClient able to send multiple mails correctly. [GB.NET.SMTP] * BUG: Make SmtpClient able to send multiple mails correctly. * NEW: Clear() is a new method that clears all attachments. --- comp/src/gb.net.smtp/.src/SmtpClient.class | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/comp/src/gb.net.smtp/.src/SmtpClient.class b/comp/src/gb.net.smtp/.src/SmtpClient.class index 00f762547..1fd4f80af 100644 --- a/comp/src/gb.net.smtp/.src/SmtpClient.class +++ b/comp/src/gb.net.smtp/.src/SmtpClient.class @@ -58,6 +58,7 @@ Private $cCustomHeaders As New String[] Private $sMessageId As String Private $sInReplyTo As String Private $iAuth As Integer +Private $iRemovePart As Integer Static Public Sub _init() @@ -66,6 +67,13 @@ Static Public Sub _init() End +'' Clear the attachments. + +Public Sub Clear() + + $aPart.Clear + +End Public Sub Add(Data As String, Optional MimeType As String, Name As String) @@ -251,11 +259,14 @@ Private Sub BeginSession() '$hSession._Debug = $bDebug + $iRemovePart = 0 + If $sBody Then hPart = New SmtpPart hPart.Data = $sBody $aPart.Add(hPart, 0) + Inc $iRemovePart Endif @@ -265,15 +276,25 @@ Private Sub BeginSession() hPart.Data = "This is a MIME " & hPart.Mime & " message." $aPart.Add(hPart, 0) bParent = True + Inc $iRemovePart Endif End +Private Sub CleanUpSession() + + $aPart.Remove(0, $iRemovePart) + $iRemovePart = 0 + +End + + Private Sub EndSession() $hSession.Send("QUIT") $hSession.Disconnect + CleanUpSession End @@ -524,6 +545,7 @@ Catch sErr = Error.Text Try $hSession.Disconnect + CleanUpSession Error.Raise("Unable to send mail: " & sErr) End @@ -551,7 +573,6 @@ End Private Sub MessageId_Write(Value As String) $sMessageId = Value - End