当前位置: 技术问答>java相关
请给一个javamail的程序实例和javamail api 的下载地址100分!
来源: 互联网 发布时间:2015-10-16
本文导语: 请给一个javamail的程序实例 要完整的例子! javamail api 的下载地址 或者是直接发送到我的邮箱:zhenhua@cosix.com.cn 谢谢! 给100分! | 我给你发了,例子在压缩包中有 | // jav...
请给一个javamail的程序实例
要完整的例子!
javamail api 的下载地址
或者是直接发送到我的邮箱:zhenhua@cosix.com.cn
谢谢!
给100分!
要完整的例子!
javamail api 的下载地址
或者是直接发送到我的邮箱:zhenhua@cosix.com.cn
谢谢!
给100分!
|
我给你发了,例子在压缩包中有
|
// java mail package http://java.sun.com/products/javamail/index.html
//java mail depends on http://java.sun.com/products/javabeans/glasgow/jaf.html
//Set your CLASSPATH to include the "mail.jar" file obtained from
// the download, as well as the current directory.
// Assuming you unzipped javamail-1_2.zip in c:download the
// following would work:
// set CLASSPATH=%CLASSPATH%;c:downloadjavamail-1.2mail.jar;.
// Also include the "activation.jar" file that you obtained from
// downloading the JavaBeans Activation Framework, in your CLASSPATH.
// set CLASSPATH=%CLASSPATH%;c:downloadactivationactivation.jar
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mail extends JFrame
{
JLabel jlSendMail = new JLabel("Send Mail");
public Mail()
{
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlSendMail);
jlSendMail.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
try{
String host = "smtp.21cn.com";//"Mail Server in your Company";
String from = "aaaa@21cn.com";//"From Email";
String to = "bbbb@21cn.com";//"To Email";
Properties props = new Properties();
Session session;
//Store store;
Transport transport;
props.put("mail.smtp.host", host);
session = Session.getInstance(props, null);
//session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from,"Ahmad"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to,"Ahmadwa"));
message.setSubject("First");
//message.setSentDate(new Date());
message.setText("Hi Emad" + (char)(10) + "How are you? This is a test mail send by java program"+new Date());
transport = session.getTransport("smtp");
transport.send(message);
System.out.println("Your Mail Send Successfully");
}
catch (MessagingException e) {System.out.println("1)" + e.toString());}
catch (UnsupportedEncodingException e) {System.out.println("2)" + e.toString());}
}
});
this.setSize(600,600);
this.setVisible(true);
}
public static void main(String args[])
{
new Mail();
}
}
//java mail depends on http://java.sun.com/products/javabeans/glasgow/jaf.html
//Set your CLASSPATH to include the "mail.jar" file obtained from
// the download, as well as the current directory.
// Assuming you unzipped javamail-1_2.zip in c:download the
// following would work:
// set CLASSPATH=%CLASSPATH%;c:downloadjavamail-1.2mail.jar;.
// Also include the "activation.jar" file that you obtained from
// downloading the JavaBeans Activation Framework, in your CLASSPATH.
// set CLASSPATH=%CLASSPATH%;c:downloadactivationactivation.jar
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mail extends JFrame
{
JLabel jlSendMail = new JLabel("Send Mail");
public Mail()
{
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlSendMail);
jlSendMail.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
try{
String host = "smtp.21cn.com";//"Mail Server in your Company";
String from = "aaaa@21cn.com";//"From Email";
String to = "bbbb@21cn.com";//"To Email";
Properties props = new Properties();
Session session;
//Store store;
Transport transport;
props.put("mail.smtp.host", host);
session = Session.getInstance(props, null);
//session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from,"Ahmad"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to,"Ahmadwa"));
message.setSubject("First");
//message.setSentDate(new Date());
message.setText("Hi Emad" + (char)(10) + "How are you? This is a test mail send by java program"+new Date());
transport = session.getTransport("smtp");
transport.send(message);
System.out.println("Your Mail Send Successfully");
}
catch (MessagingException e) {System.out.println("1)" + e.toString());}
catch (UnsupportedEncodingException e) {System.out.println("2)" + e.toString());}
}
});
this.setSize(600,600);
this.setVisible(true);
}
public static void main(String args[])
{
new Mail();
}
}