Archived

This topic is now archived and is closed to further replies.

d_aelion

[java] Email from Java applet/application???

Recommended Posts

d_aelion    122
Hey guys, Im working on a game Im going to release soon and I was wondering if any one knew of a way to send email from an application or applet? I''m not looking for anything too terribly involved but anything you guys know about would be much appreciated. Thanks in advance!

Share this post


Link to post
Share on other sites
WayfarerX    130
Well, there''s JavaMail. You can use it from an application. For an applet, send the email data to a servlet on the server, and have it send it through JavaMail.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
The first time I did this was right back when JMail was in EA so I used the following work around (Note I ripped this from old code and it won''t work as a straight copy/paste job). The basic premise is to create a mailto: url and post the mail via that programaticaly.
As follows:

System.getProperties().put("mail.host",MAILHOST);
try{
URL u = new URL("mailto:" + To.getText());
System.out.println(To.getText());
URLConnection c = u.openConnection();
c.setDoInput(false);
c.setDoOutput(true);
c.connect();
out = new PrintWriter(new OutputStreamWriter(c.getOutputStream()));
out.println("From:" + From.getText());
out.println("To:" + To.getText());
out.println("Subject:" + Subject.getText());
out.println("";
for(;{
out.println(TEXT);
break;
}
out.flush();
out.close();
c.close()
}catch(Exception e){e.printStackTrace();}

Share this post


Link to post
Share on other sites
d_aelion    122
All right guys, thanks for your help. I found a different solution though that works for what I need to do. Here it is:

try {
Runtime.getRuntime ().exec ("rundll32.exe url.dll,
FileProtocolHandler mailto:joe@anywhere.com");
}
catch (Exception exception) {}

Basically it just loads the dll that is used to run commands and the dll to parse url strings. After that it will load whichever mail client the user has set as default (Outlook, etc..) and after that its up to it. Pretty neat huh?
This just works for Windows, but I''m sure there are other similar calls for other OS''s.

Share this post


Link to post
Share on other sites