aspose file tools*
The moose likes I/O and Streams and the fly likes How to configure the MailTo protocol. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to configure the MailTo protocol." Watch "How to configure the MailTo protocol." New topic
Author

How to configure the MailTo protocol.

Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
Greetings,

I am testing the following program that is supposed to send an email to the author of a book ( Java I/O by Elliotte Rusty Harold ). The program is copied from the same book, chapter 5, Network Streams.


When I execute this program I get a java.net.UnknownHostException for my line 19 - which corresponds to the following line.
Following is the stacktrace.

java.net.UnknownHostException: mailhost
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.NetworkClient.openServer(Unknown Source)
at sun.net.smtp.SmtpClient.openServer(Unknown Source)
at sun.net.smtp.SmtpClient.<init>(Unknown Source)
at sun.net.www.protocol.mailto.MailToURLConnection.connect(Unknown Source)
at harold.chapter5.MailClient.main(MailClient.java:19)


The author states that this program will run only in environments that support the mailto protocol. Thus it works under Sun's JDK and may not work in other VMs. I'm using JDK 1.7 update 45. So that should still be Sun's JDK, right?

The author further states that this program also requires that the local host be running an SMTP server, or that the system property mail.host must contain the name of an accessible SMTP server, or that a machine in the local domain named mailhost be running an SMTP server. Also the security manager must permit network connections to that server.

I printed the System.getProperty("mail.host") and it printed null. My Regedit has following entry for the mailto key.

Name | Type | Data
(Default) | REG_SZ | URL:MailTo Protocol
EditFlags | REG_BINARY | 02 00 00 00
URL Protocol | REG_SZ

If I click on DefaultIcon, it has following value.
Name | Type | Data
(Default) | REG_SZ | C:\PROGRA~1\MICROS~1\Office14\OUTLOOK.EXE,-9403

If I click on shell, it has this.
Name | Type | Data
(Default) | REG_SZ | open

Under shell, if I click on open, it shows this.
Name | Type | Data
(Default) | REG_SZ | (value not set)

Under open, if I click on command, it shows the following on the right hand side tab.
Name | Type | Data
(Default) | REG_SZ | "C:\PROGRA~1\MICROS~1\Office14\OUTLOOK.EXE" -c IPM.Note...

I am able to send a mail using the JavaMail API ( the standard program that makes use of the SMTP protocol - the one in which we set smtp host, user, password, protocol, auth etc, create a Session, and a Message and set From, Recipient, Subject, Text, and call the Transport.send(message) ).

But I can't figure how the MailTo protocol does not require any of this configuration code, how it can connect to a URL of the form "mailto:<some email address>" and once we have an OutputStream from this URLConnection we can directly write to it which will be delivered to the intended recipient in the form of an email. I had never heard of MailTo protocol before. I'm guessing once it is configured, it may use my SMTP settings behind the scene. But anyway, my program is giving me an exception. What should be my next step for setting the value of mail.host correctly?

Thanks.

E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
You can set a system property using the System.setProperty method.
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
E Armitage wrote:You can set a system property using the System.setProperty method.


Thanks for responding, E Armitage. Yeah I would like to set this value. But the problem is I'm not sure what value it should have. My registry vars suggests the MailTo protocol is configured to use Outlook.exe and I use outlook for my work email. I don't know what should be mail.host for MailTo protocol to work.

For SMTP protocol to work in a program that makes use of the JavaMail API, I know the settings. I mean if say I'm using GMAIL or Yahoo SMTP/SMTPS with the Transport.send(message), I know what settings I should have.
But for the current registry entries that are configured for the MailTo protocol, I don't know what value my "mail.host" property should have.

Is there a way I could look it up somewhere in some settings I have on my computer?

Thanks.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
If you are doing this at work then you might not be allowed to use your company's mail server to send out emails to anyone from a program. Otherwise you can ask your administrators (whoever installed) outlook for you for the details.
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
you can ask your administrators (whoever installed) outlook for you for the details.


I will do that. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42611
    
  65
I advice to use the JavaMail API instead of trying to make it work with the URL approach (with which you will hit its limits sooner rather than later).


Ping & DNS - my free Android networking tools app
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
Ulf Dittmer wrote:I advice to use the JavaMail API instead of trying to make it work with the URL approach (with which you will hit its limits sooner rather than later).


Thanks, Ulf. For the reason you mention, I will skip setting it up and testing how it works - cause I may probably never use it. So it isn't worth the pain anyway.

Since I know how to send an email/attachments etc using JavaMail API already, I will switch to the next topic.
 
Consider Paul's rocket mass heater.
 
subject: How to configure the MailTo protocol.