| | |
Java Mailing
A program that can send mails. This requires that you have activation.jar and mail.jar in you classpath.
/* to run this example u may require activation.jar and mail.jar in ur classpath */ import javax.mail.*; import javax.mail.internet.*; import java.util.*; import javax.activation.*; import java.io.*; public class SimpleSender { public static void main(String args[]) { try { String smtpServer=args[0]; String to=args[1]; String from=args[2]; String body=args[3]; send(smtpServer, to, from,body); } catch (Exception ex) { System.out.println("Usage :\njava SimpleSender server to from body"); } System.exit(0); } public static void send(String smtpServer, String to, String from, String body) { try { Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); Session session = Session.getDefaultInstance(props, null); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false)); msg.setSubject("Test Mail thru java"); msg.setContent(body,"text/plain"); msg.setSentDate(new Date()); Transport.send(msg); System.out.println("Message sent OK."); } catch (Exception ex) { ex.printStackTrace(); } } }
0
•
•
•
•
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
activation.jar is part of JavaBeans Activation Framework 1.1 and can be download here http://java.sun.com/products/javabea....html#download
Similar Threads
- mailing (ASP.NET)
- Mailing to an array (PHP)
- Mailing issue (PHP)
- Linux Mailing (Getting Started and Choosing a Distro)
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows



