• Post Reply Bookmark Topic Watch Topic
  • New Topic

sending email in java not working

 
jagdish waran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

code for sending email. i had taken it from a website. but it is not working


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

public class MailExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2];

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

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

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

// Define message
MimeMessage message = new MimeMessage(session);

// Set the from address
message.setFrom(new InternetAddress(from));
message.setSender(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));

// Set the subject
message.setSubject("Hello JavaMail");

// Set the content
message.setText("Welcome to JavaMail");

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

the above code in compiling successfully. but iam not able to receive any email. the email addresses given on the arguments and the host name are correct. pls help me out with some solutions

or pls give me a site where ican read these process completely and work on it.

thanks
jagdish
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most email servers require you to use authentication, i.e. to provide the password for your account.

You can also call "session.setDebug(true)", which will cause all kinds of useful debugging information to be printed.

An extensive tutorial with examples is at http://java.sun.com/developer/onlineTraining/JavaMail/contents.html
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jagdish waran:
or pls give me a site where ican read these process completely and work on it.
I'm not quite sure what this means, but look at the JavaMail FAQ.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!