This week's book giveaway is in the Game Development forum.
We're giving away four copies of Badass: Making Users Awesome and have Kathy Sierra on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes What should be the value of 'host' when I send an e-mail? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "What should be the value of Watch "What should be the value of New topic

What should be the value of 'host' when I send an e-mail?

Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
I'm reading about Java Mail API but I have some problem with that. Actually I'm writing a web gallery & I have to use this API so that users can share photos through e-mail & also to send notification in new photos.

...Well I know that the protocols to use are SMTP for sending mail and POP3 or IMAP for receiving mail, and we need to access to a mail server.

But I don't know exactly what can be the value of "host". (String host = "?"

When I run the following program it gives me this exception :

javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Unknown SMTP host:;
nested exception is:
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at SimpleSender.send(
at SimpleSender.main(

(Here is the code I have copied from somewhere, to send an attachment: )

package mail;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class sendwithattachment {
public static void main (String args[])
throws Exception {
String host = ""; ////////// I don't know what I should put here
String from = "";
String to = "";
String fileAttachment = "C://MainFolder/sth.rtf";

// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("", host);

// Get session
Session session =
Session.getInstance(props, null);

// Define message
MimeMessage message =
new MimeMessage(session);
new InternetAddress(from));
new InternetAddress(to));
"Hello JavaMail Attachment -- This is Maryam!");

// create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart();

//fill message
messageBodyPart.setText("I did it!");

Multipart multipart = new MimeMultipart();

// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
new DataHandler(source));

// Put parts in message

// Send the message
Transport.send( message );

What can be the problem? & should I add any jar file to my project?

Thanks a ton,

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

The host value is the host server that provides support for whatever protocol you are using. Yuo have defined a server that appears to be Yahoo. First thing to check: does it exist? Next thing to check: can you access it via SMTP? Its an internet email provider, so I'd guess no for the second question, but its the sort of question you can answer quickest by speaking to the server admin.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: What should be the value of 'host' when I send an e-mail?