Exception "the system cannot find the path specified" appears occasionally when sending e-mails

299 Views Asked by At

I have developed an application that sends messages using SMTP to a local Apache James server. One run of the program takes approximately 3-10 minutes. I have the program ran for hours in a row for a performance test, which works fine onUbuntu. However, when I run the program on Windows 10 I receive the following stack trace after approx. 2-3 hours runtime:

Caused by: com.sun.mail.smtp.SMTPSendFailedException: 451 4.0.0 Error processing message: The system cannot find the path specified

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2374)
    at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2095)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1301)
    at org.bihealth.mi.easybus.implementations.email.ConnectionIMAP.send(ConnectionIMAP.java:294)
    ... 6 more

The problem occurred on two different Windows 10 installations, the firewalls of the systems were stopped. The coding of the send method and the properties are listed below. In case of an error, the method is called 10 times in a row with a waiting time of 30 seconds between the sending retries before the above mentioned exception is thrown. The difference to many other questions with the message "the system cannot find the path specified" is, that the error only occurs sometimes (2-3h), not always.

Do you have any hints what the underlying issue might be? Any help is much appreciated!

protected synchronized void send(String recipient, String subject, String body, Object attachment) throws BusException {

synchronized(propertiesSending) {

    // Make sure we are ready to go
    try {
        if (session == null) {
            session = Session.getInstance(propertiesSending);
        }
    } catch (Exception e) {
        throw new BusException("Error establishing or keeping alive connection to mail server", e);
    }

    try {
        
        // Create message
        MimeMessage email = new MimeMessage(session);
       
        // Add sender and recipient
        email.setRecipient(RecipientType.TO, new InternetAddress(recipient));
        email.setSender(new InternetAddress(getEmailAddress()));
        email.setFrom(new InternetAddress(getEmailAddress()));
        email.setSubject(subject);
        
        // Add body
        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
        mimeBodyPart.setContent(body, "text/plain");
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mimeBodyPart);

        // Add attachment
        if (attachment != null) {
            mimeBodyPart = new MimeBodyPart();
            mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
            byte[] attachmentBytes = getByteArrayOutputStream(attachment);
            mimeBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(attachmentBytes, "application/octet-stream")));
            mimeBodyPart.setFileName(FILENAME_MESSAGE);
            multipart.addBodyPart(mimeBodyPart);
            
            // Add statistics
            Bus.numberMessagesSent.incrementAndGet();
            Bus.totalSizeMessagesSent.addAndGet(attachmentBytes.length);
        }
        
        // Compose message
        email.setContent(multipart);

        // Send
        Transport.send(email, getEmailAddress(), password);                
        logger.debug("Message sent logged", new Date(), "Message 

sent logged", subject);
        } catch (Exception e) {
            throw new BusException("Unable to send message", e);
        }
    }
 }


this.propertiesSending = new Properties();
        this.propertiesSending.put("mail.user", getEmailAddress());
        this.propertiesSending.put("mail.from", getEmailAddress());
        this.propertiesSending.put("mail.transport.protocol", "smtp");
        this.propertiesSending.put("mail.smtp.host", settings.getSMTPServer());
        this.propertiesSending.put("mail.smtp.port", String.valueOf(settings.getSMTPPort()));
        this.propertiesSending.put("mail.smtp.auth", "true");
1

There are 1 best solutions below

0
On

It seemed to be rather an issue with the used Apache James e-mail server, which has been discussed elsewhere already: https://issues.apache.org/jira/browse/JAMES-1832.

Simply starting Apache James with run.bat instead of as a service solved the issue for me