diff --git a/gxmail/src/main/java/com/genexus/internet/SMTPSession.java b/gxmail/src/main/java/com/genexus/internet/SMTPSession.java index 1ee39c2a1..2b50e0eb9 100644 --- a/gxmail/src/main/java/com/genexus/internet/SMTPSession.java +++ b/gxmail/src/main/java/com/genexus/internet/SMTPSession.java @@ -623,8 +623,25 @@ private void sendAttachment(String sTime, String fileNamePath, String attachment try { fis = new FileInputStream(attachmentPath + fileNamePath); is = fis; - } - catch (FileNotFoundException e) { + + println(getNextMessageIdMixed(sTime, false)); + println("Content-Type: " + "application/octet-stream"); + println("Content-Transfer-Encoding: " + "base64"); + println("Content-Disposition: " + "attachment; filename=\"" + GXMailer.getEncodedString(fileName) + "\""); + println(""); + + int BUFFER_SIZE = 4096; + byte[] buffer = new byte[BUFFER_SIZE]; + OutputStream base64Output = new Base64OutputStream(outStream); + int n = is.read(buffer, 0, BUFFER_SIZE); + while (n >= 0) { + base64Output.write(buffer, 0, n); + n = is.read(buffer, 0, BUFFER_SIZE); + } + base64Output.flush(); + outStream.writeBytes(CRLF); + outStream.flush(); + } catch (FileNotFoundException e) { log ("11 - FileNotFound " + e.getMessage()); throw new GXMailException("Can't find " + attachmentPath + fileNamePath, MAIL_InvalidAttachment); } finally { @@ -633,24 +650,6 @@ private void sendAttachment(String sTime, String fileNamePath, String attachment if (fis != null) fis.close(); } - - println(getNextMessageIdMixed(sTime, false)); - println("Content-Type: " + "application/octet-stream"); - println("Content-Transfer-Encoding: " + "base64"); - println("Content-Disposition: " + "attachment; filename=\"" + GXMailer.getEncodedString(fileName) + "\""); - println(""); - - int BUFFER_SIZE = 4096; - byte[] buffer = new byte[BUFFER_SIZE]; - OutputStream base64Output = new Base64OutputStream(outStream); - int n = is.read(buffer, 0, BUFFER_SIZE); - while (n >= 0) { - base64Output.write(buffer, 0, n); - n = is.read(buffer, 0, BUFFER_SIZE); - } - base64Output.flush(); - outStream.writeBytes(CRLF); - outStream.flush(); } private void println(String s) throws IOException