@@ -135,7 +135,6 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
135
135
*/
136
136
public function executeCommand (string $ command , array $ codes ): string
137
137
{
138
- $ this ->getLogger ()->debug (sprintf ('Email transport "%s" sent command "%s" ' , __CLASS__ , trim ($ command )));
139
138
$ this ->stream ->write ($ command );
140
139
$ response = $ this ->getFullResponse ();
141
140
$ this ->assertResponseCode ($ response , $ codes );
@@ -145,18 +144,22 @@ public function executeCommand(string $command, array $codes): string
145
144
146
145
protected function doSend (SentMessage $ message ): void
147
146
{
148
- $ envelope = $ message ->getEnvelope ();
149
- $ this ->doMailFromCommand ($ envelope ->getSender ()->toString ());
150
- foreach ($ envelope ->getRecipients () as $ recipient ) {
151
- $ this ->doRcptToCommand ($ recipient ->toString ());
152
- }
147
+ try {
148
+ $ envelope = $ message ->getEnvelope ();
149
+ $ this ->doMailFromCommand ($ envelope ->getSender ()->toString ());
150
+ foreach ($ envelope ->getRecipients () as $ recipient ) {
151
+ $ this ->doRcptToCommand ($ recipient ->toString ());
152
+ }
153
153
154
- $ this ->executeCommand ("DATA \r\n" , [354 ]);
155
- foreach (AbstractStream::replace ("\r\n. " , "\r\n.. " , $ message ->toIterable ()) as $ chunk ) {
156
- $ this ->stream ->write ($ chunk );
154
+ $ this ->executeCommand ("DATA \r\n" , [354 ]);
155
+ foreach (AbstractStream::replace ("\r\n. " , "\r\n.. " , $ message ->toIterable ()) as $ chunk ) {
156
+ $ this ->stream ->write ($ chunk , false );
157
+ }
158
+ $ this ->stream ->flush ();
159
+ $ this ->executeCommand ("\r\n. \r\n" , [250 ]);
160
+ } finally {
161
+ $ message ->appendDebug ($ this ->stream ->getDebug ());
157
162
}
158
- $ this ->stream ->flush ();
159
- $ this ->executeCommand ("\r\n. \r\n" , [250 ]);
160
163
}
161
164
162
165
protected function doHeloCommand (): void
@@ -237,8 +240,6 @@ private function assertResponseCode(string $response, array $codes): void
237
240
list ($ code ) = sscanf ($ response , '%3d ' );
238
241
$ valid = \in_array ($ code , $ codes );
239
242
240
- $ this ->getLogger ()->debug (sprintf ('Email transport "%s" received response "%s" (%s). ' , __CLASS__ , trim ($ response ), $ valid ? 'ok ' : 'error ' ));
241
-
242
243
if (!$ valid ) {
243
244
throw new TransportException (sprintf ('Expected response code "%s" but got code "%s", with message "%s". ' , implode ('/ ' , $ codes ), $ code , trim ($ response )), $ code );
244
245
}
0 commit comments