Free Support Forum - aspose.com

OperationCanceledException: Operation has been canceled

Hi Team,

I am using Aspose Email version 20.6.

I have a problem that sending mail with IMAP and receiving mail from SMTP does not work with my provider.

With similar credentials, I have tried on thunderbird and I was able to send and receive emails.

While trying to send an Email, I get the following exception:

OperationCanceledException: Operation has been canceled

The same occurs while receiving email. No email is received at the test account.

Please find attached the test project along with the test credentials.

AsposeSendReceiveMail.zip (7.2 KB)

Please kindly do not share the credentials outside the relevant team.

Could you please look into the issue and test what the problem is?

Thanks and Regards,
Arne

@arne411,

I have opened a ticket with ID EMAILJAVA-34723 in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that we may notify you once issue will be addressed.

@arne411,

You have used IMAP port(143) for SmtpClient. SMTP uses 587 port.

Code snippet:

EmailClient.setSocketsLayerVersion2(true);

// SMTP PORT 587
SmtpClient smtpClient = new SmtpClient("mail.host.de", 587, "user", "pwd");
smtpClient.setUseTnef(false);
smtpClient.setSecurityOptions(SecurityOptions.SSLExplicit);
smtpClient.noop();

// IMAP PORT 143
ImapClient imapClient = new ImapClient("mail.host.de", 143, "user", "pwd");
imapClient.setSecurityOptions(SecurityOptions.SSLExplicit);
imapClient.noop();

Hi Team,

I have changed the port to 587 and included smtpClient.noop().

Still the problem persists and I get “OperationCanceledException”.

Could you please update me if you have observed the same exception with the test credentials?

Thanks and Regards,
Arne

@arne411,

Your scenario also has the issue is related to certificate validation error. Can you please try using the suggested option.

Enable Java debug logging:

System.setProperty("javax.net.debug","all");

Log:

sun.security.validator.ValidatorException:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target

We can import certificate to java cacerts keystore or ignore certificate validation:


import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public static SSLSocketFactory getSSLSocketFactory() {
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
        }

        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return new java.security.cert.X509Certificate[] {};
        }
    } };

    try {
        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

        return sslContext.getSocketFactory();
    } catch (java.lang.Exception e) {
        throw new RuntimeException(e);
    }
}

public final void test()
{
    System.setProperty("javax.net.debug","all");

    EmailClient.setSocketsLayerVersion2(true);
    EmailClient.setSocketsLayerVersion2SSLSocketFactory(getSSLSocketFactory());

    SmtpClient smtpClient = new SmtpClient("mail.host.de", 587, "user", "pwd");
    smtpClient.setUseTnef(false);
    smtpClient.setSecurityOptions(SecurityOptions.SSLExplicit);
    smtpClient.noop();
} 

Hi Team,

Thanks, the above solution works.

You may now close the issue.

Thanks and Regards,
Arne

@arne411,

It’s good to know that things are working fine on your end.