首页 文章 精选 留言 我的

精选列表

搜索[药械客户管理],共10012篇文章
优秀的个人博客,低调大师

简单的邮件客户

运行界面如下: 源代码如下:(本程序使用的是Merak mail server) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 package com.zzk; /** * @author 任文超 * @version 1.0 * */ import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; import java.util.Properties; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class SendMailFrame extends JFrame { private JTextArea ta_text; private JTextField tf_title; private JTextField tf_send; private JTextField tf_receive; private Session session; // 定义Session对象 private String sendHost = "localhost" ; // 定义发送邮件的主机 private String sendProtocol= "smtp" ; // 定义使用的发送协议 public static void main(String args[]) { EventQueue.invokeLater( new Runnable() { public void run() { try { SendMailFrame frame = new SendMailFrame(); frame.init(); frame.setVisible( true ); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame */ public SendMailFrame() { super (); setTitle( "发送邮件窗体" ); getContentPane().setLayout( null ); setBounds( 100 , 100 , 439 , 299 ); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel(); label.setForeground( new Color( 0 , 0 , 255 )); label.setFont( new Font( "" , Font.BOLD, 22 )); label.setText( "发送电子邮件" ); label.setBounds( 144 , 10 , 185 , 24 ); getContentPane().add(label); final JLabel label_1 = new JLabel(); label_1.setText( "收件人地址:" ); label_1.setBounds( 22 , 42 , 85 , 18 ); getContentPane().add(label_1); tf_receive = new JTextField(); tf_receive.setBounds( 113 , 40 , 287 , 22 ); getContentPane().add(tf_receive); final JLabel label_2 = new JLabel(); label_2.setText( "发件人地址:" ); label_2.setBounds( 22 , 68 , 78 , 18 ); getContentPane().add(label_2); tf_send = new JTextField(); tf_send.setBounds( 113 , 66 , 287 , 22 ); getContentPane().add(tf_send); final JLabel label_3 = new JLabel(); label_3.setText( "主 题:" ); label_3.setBounds( 32 , 92 , 66 , 18 ); getContentPane().add(label_3); tf_title = new JTextField(); tf_title.setBounds( 113 , 94 , 287 , 22 ); getContentPane().add(tf_title); final JLabel label_4 = new JLabel(); label_4.setText( "正 文:" ); label_4.setBounds( 34 , 128 , 66 , 18 ); getContentPane().add(label_4); final JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds( 113 , 128 , 287 , 91 ); getContentPane().add(scrollPane); ta_text = new JTextArea(); scrollPane.setViewportView(ta_text); final JButton btn_send = new JButton(); btn_send.addActionListener( new ActionListener() { public void actionPerformed( final ActionEvent e) { String fromAddr = tf_send.getText().trim(); String toAddr = tf_receive.getText().trim(); // 真实存在的目标邮件地址 String title = tf_title.getText().trim(); String text = ta_text.getText().trim(); try { sendMessage(fromAddr, toAddr, title, text); } catch (Exception e1) { e1.printStackTrace(); } } }); btn_send.setText( "发 送" ); btn_send.setBounds( 144 , 225 , 78 , 28 ); getContentPane().add(btn_send); final JButton btn_exit = new JButton(); btn_exit.addActionListener( new ActionListener() { public void actionPerformed( final ActionEvent e) { System.exit( 0 ); } }); btn_exit.setText( "退 出" ); btn_exit.setBounds( 279 , 225 , 78 , 28 ); getContentPane().add(btn_exit); } public void init() throws Exception { Properties props = new Properties(); // 创建属性对象 props.put( "mail.transport.protocol" , sendProtocol); // 指定邮件传输协议 props.put( "mail.smtp.class" , "com.sun.mail.smtp.SMTPTransport" ); //指定传输协议使用的类 props.put( "mail.smtp.host" , sendHost); // 定义发送邮件的主机 session = Session.getDefaultInstance(props); // 创建Session对象 } /** * @param fromAddr 发送者 * @param toAddr 接收者 * @param title 主题 * @param text 内容 * @throws Exception 异常 */ public void sendMessage(String fromAddr,String toAddr,String title,String text) throws Exception { Message msg = new MimeMessage(session); // 创建Message对象 InternetAddress[] toAddrs = InternetAddress.parse(toAddr, false ); // 创建接收方的InternetAddress对象 msg.setRecipients(Message.RecipientType.TO, toAddrs); // 指定接收方 msg.setSentDate( new Date()); // 指定接发送日期 msg.setSubject(title); // 设置主题 msg.setFrom( new InternetAddress(fromAddr)); // 指定发送者 msg.setText(text); // 指定发送内容 Transport.send(msg); // 发送邮件 JOptionPane.showMessageDialog( null , "邮件发送成功。" ); } } ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2011/10/19/2217431.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册