• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

sending mails through java

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
Rancher
Posts: 43011
76
  • 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.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!