wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes sending mails through java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "sending mails through java" Watch "sending mails through java" New topic
Author

sending mails through java

vidhyasagar reddy
Ranch Hand

Joined: Jul 05, 2005
Posts: 40
while sending the mails it is showing the error at run time

*********************code******************



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

public class SendMail
{
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException {
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
System.out.println("before sending");
//Transport.send(msg);
Transport.send(msg,addressTo);
}


public static void main(String args[]) throws MessagingException
{

SendMail o = new SendMail();
String to[]={"ursagar_in@yahoo.co.in"};
String from="ursagar_in@yahoo.co.in";
String msg="This is password";
String sub="Message from Here To Win";
System.out.println("sending...");
o.postMail(to,sub,msg,from);
System.out.println("sending over...");

}
}


************************************************

***********************Error************************

At run time it is showing that unable to connect to the smtp port 25

*****************************************************


some body told me that we have to install the james mail server for sending mails through java , i have downloaded that and while running the bin/run.bat

1.It is showing the error that Error while building apps/james/SAR-INF/config.xml

can any body tell em how to install the james server or tell me ur procedure for sending mails through java
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You've posted this in "Games Development"; I think you meant to post in "Other Java APIs." I will move this there for you.


[Jess in Action][AskingGoodQuestions]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42920
    
  68
I can't connect to smtp.jcom.net on port 25 either. You should check whether that is in fact the correct mail server address.
James is an email server, but you're building an email client, so, no, you don't need James. javax.mail implements the standard email protocols - it can connect to any email server that also supports these standards (which means just about all of them). You shouldn't even have to know what kind of server you're connecting to, and it certainly doesn't need to be written in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending mails through java