首页 文章 精选 留言 我的

精选列表

搜索[数据库客户端],共10027篇文章
优秀的个人博客,低调大师

简单的邮件客户端

运行界面如下: 源代码如下:(本程序使用的是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,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

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部分的功能。

用户登录
用户注册