• Post Reply Bookmark Topic Watch Topic
  • New Topic

sending mails through java  RSS feed

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


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);

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

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

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.setContent(message, "text/plain");
System.out.println("before sending");

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 over...");




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
Posts: 24217
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
Posts: 42972
  • 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
Boost this thread!