We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,449 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Java Mailing

0
By cheenu78 on Jun 30th, 2005 4:35 pm

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


}

I do not know where I can get activation.jar and mail.jar

monga monga
Newbie Poster
2 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Yes, it is not explained where to get these jar files.

AhmedHan
Junior Poster in Training
71 posts since Apr 2005
Reputation Points: 13
Solved Threads: 1
Skill Endorsements: 0

mail.jar is part of JavaMail 1.4 and you can download mail.jar from here http://java.sun.com/products/javamail/downloads/index.html

activation.jar is part of JavaBeans Activation Framework 1.1 and can be download here http://java.sun.com/products/javabeans/jaf/downloads/index.html#download

peter_budo
Code tags enforcer
Moderator
15,812 posts since Dec 2004
Reputation Points: 2,871
Solved Threads: 944
Skill Endorsements: 52

What do i give as command line arguments for arg[0],arg[1],arg[2] can u be more specific

brittoonline
Newbie Poster
4 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

How do i solve this error?

"The import.javax.mail cannot be resolved"

Jocamps
Junior Poster
120 posts since Jun 2007
Reputation Points: 30
Solved Threads: 7
Skill Endorsements: 0

how to send links in the above code

balagangadharm
Light Poster
26 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0861 seconds using 2.66MB