This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending mails through java

 
vidhyasagar reddy
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've posted this in "Games Development"; I think you meant to post in "Other Java APIs." I will move this there for you.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic