Java Mailing

cheenu78 cheenu78 is offline Offline Jun 30th, 2005, 7:35 am |
0
A program that can send mails. This requires that you have activation.jar and mail.jar in you classpath.
Quick reply to this message  
Java Syntax
  1. /*
  2. to run this example u may require activation.jar and mail.jar in ur classpath
  3. */
  4.  
  5. import javax.mail.*;
  6. import javax.mail.internet.*;
  7. import java.util.*;
  8. import javax.activation.*;
  9. import java.io.*;
  10. public class SimpleSender
  11. {
  12. public static void main(String args[])
  13. {
  14. try
  15. {
  16. String smtpServer=args[0];
  17. String to=args[1];
  18. String from=args[2];
  19. String body=args[3];
  20. send(smtpServer, to, from,body);
  21. }
  22. catch (Exception ex)
  23. {
  24. System.out.println("Usage :\njava SimpleSender server to from body");
  25. }
  26. System.exit(0);
  27. }
  28.  
  29. public static void send(String smtpServer, String to, String from, String body)
  30. {
  31. try
  32. {
  33. Properties props = System.getProperties();
  34. props.put("mail.smtp.host", smtpServer);
  35. Session session = Session.getDefaultInstance(props, null);
  36. MimeMessage msg = new MimeMessage(session);
  37. msg.setFrom(new InternetAddress(from));
  38. msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
  39. msg.setSubject("Test Mail thru java");
  40. msg.setContent(body,"text/plain");
  41. msg.setSentDate(new Date());
  42. Transport.send(msg);
  43. System.out.println("Message sent OK.");
  44. }
  45. catch (Exception ex)
  46. {
  47. ex.printStackTrace();
  48. }
  49. }
  50.  
  51.  
  52. }
0
monga monga monga monga is offline Offline | Feb 8th, 2006
I do not know where I can get activation.jar and mail.jar
 
0
AhmedHan AhmedHan is offline Offline | Feb 18th, 2006
Yes, it is not explained where to get these jar files.
 
0
peter_budo peter_budo is offline Offline | Feb 25th, 2007
mail.jar is part of JavaMail 1.4 and you can download mail.jar from here http://java.sun.com/products/javamai...ads/index.html

activation.jar is part of JavaBeans Activation Framework 1.1 and can be download here http://java.sun.com/products/javabea....html#download
 
0
brittoonline brittoonline is offline Offline | Mar 29th, 2007
What do i give as command line arguments for arg[0],arg[1],arg[2] can u be more specific
 
0
Jocamps Jocamps is offline Offline | Jun 24th, 2007
How do i solve this error?

"The import.javax.mail cannot be resolved"
 
0
balagangadharm balagangadharm is offline Offline | Nov 7th, 2007
how to send links in the above code
 
 

Message:


Similar Threads
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC