Nilhcem/FakeSMTP

Option to choose the email client

Closed this issue · 2 comments

I'm using ubuntu 14.04 x86_64 with java 7 and FakeSMTP cannot open emails when I double clicked them.

From your code I can see that you are using Desktop.open() to open the emails. I did a test that fails in my case

import java.awt.*;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class TestDesktop {
    public static void main(String[] args) throws IOException {
        boolean desktopSupported = Desktop.isDesktopSupported();
        System.out.println("desktopSupported = " + desktopSupported);
        Desktop desktop = Desktop.getDesktop();
        System.out.println("desktop = " + desktop);
        Path path = Paths.get("/", "home", "fsousa", "xxx.eml");
        boolean exists = path.toFile().exists();
        System.out.println("exists = " + exists);
        desktop.open(path.toFile());
    }
}
desktopSupported = true
desktop = java.awt.Desktop@223d7457
exists = true
Exception in thread "main" java.io.IOException: Failed to show URI:file:/home/fsousa/xxx.eml
    at sun.awt.X11.XDesktopPeer.launch(XDesktopPeer.java:114)
    at sun.awt.X11.XDesktopPeer.open(XDesktopPeer.java:77)
    at java.awt.Desktop.open(Desktop.java:272)
    at com.egoi.megan.TestDesktop.main(TestDesktop.java:17)

Testing with a text file (*.txt) works, but fails for *.eml

Under OSX works fine.

The user should be able to choose another application to open the email.

Thanks
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

I can confirm this issue on Ubuntu 14.04 x86_64 with Java 7. It seems that Desktop.open() is a bit buggy (take a look at few links: 1, 2).

I've fixed the issue simply by executing command to fire up Thunderbird by Runtime.getRuntime().exec(...). I've added command line parameter which can be used to define executable for opening *.eml files as below:

java -jar fakeSMTP-VERSION.jar -e thunderbird
java -jar fakeSMTP-VERSION.jar --eml-viewer thunderbird

Tested also on OSX, proper invocation for Thunderbird:

java -jar fakeSMTP-VERSION.jar --eml-viewer "open -a Thunderbird"

And for Mail.app:

java -jar fakeSMTP-VERSION.jar --eml-viewer "open -a Mail"

So it was tested on Linux with Thunderbird and on OSX with Thunderbird and Mail. I can't test on Windows right now but it should work fine :)

I've submitted PR: #22 You can merge it if you think it's okay and may be useful :)

Thanks for both the issue and the PR. #22 is merged.