package lianxi;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Login() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JLabel label = new JLabel("\u90AE\u7BB1");
contentPane.add(label);
textField = new JTextField();
textField.setText("\u7528\u6237\u540D");
contentPane.add(textField);
textField.setColumns(20);
JLabel label_1 = new JLabel("@");
contentPane.add(label_1);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"263.net", "qq.com", "sina.com"}));
contentPane.add(comboBox);
JLabel label_2 = new JLabel("\u5BC6\u7801");
contentPane.add(label_2);
passwordField = new JPasswordField();
passwordField.setColumns(20);
contentPane.add(passwordField);
JButton button = new JButton("\u767B\u9646");
contentPane.add(button);
pack();
}
}
昨晚刚回答过一样的问题
package com.gpt.util.email;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import com.gpt.util.PropertiesUtil;
/**
*
* Java邮件发送类,使用javaMail类进行邮件发送
* by CKQ
* */
public class MailUtil {
//邮件服务器
private static String mail_host=(String)PropertiesUtil.getMap().get("mail_host");//"smtp.yeah.net";
//邮件服务器端口
private static int port=Integer.valueOf((String)PropertiesUtil.getMap().get("mail_port"));//25;
//邮件协议
private static String mail_transport_protocol=(String)PropertiesUtil.getMap().get("mail_transport_protocol");//"smtp";
//需要smtp验证
private static String mail_smtp_auth=(String)PropertiesUtil.getMap().get("mail_smtp_auth");//"true";
//发送人用户名
private static String username=(String)PropertiesUtil.getMap().get("mail_username");//"wujianhui321@yeah.net";
//发送人密码
private static String password=(String)PropertiesUtil.getMap().get("mail_password");//"xxxxxx";
//发送纯文本邮件
public static boolean sendSimpleMail(String from,String to,String subject,String content) {
boolean result=true;
try {
Properties prop=new Properties();
prop.setProperty("mail.host", mail_host);
prop.setProperty("mail.transport.protocol", mail_transport_protocol);
prop.setProperty("mail.smtp.auth", mail_smtp_auth);
//经验证qq邮箱需要添加一下两条记录,否则失败,其他暂时不知道,这是安全协议所需要的类 add by CKQ 2017-7-19
prop.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.smtp.socketFactory.port", String.valueOf(port));
Session session=Session.getInstance(prop);
//设置为debug模式 ,生产环境应该关掉
session.setDebug(true);
//获得transport对象
Transport ts=session.getTransport();
//连上邮件服务器
ts.connect(mail_host,port, username,password);
//创建邮件
MimeMessage message=new MimeMessage(session);
//设置发送人
message.setFrom(new InternetAddress(from));
//设置接收人
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
//设置主题
message.setSubject(subject);
//设置内容
message.setContent(content,"text/html;charset=UTF-8");
//发送邮件
ts.sendMessage(message, message.getAllRecipients());
//关闭连接
ts.close();
} catch (Exception e) {
e.printStackTrace();
result=false;
}
return result;
}
//发送带图片的邮件
public static boolean sendImageMail(String from,String to,String subject,String absoluteImagePath) throws Exception{
boolean result=true;
try {
//获取图片后缀
String suffix=absoluteImagePath.substring(absoluteImagePath.lastIndexOf(".")+1,absoluteImagePath.length()) ;
//定义contentId,图片到达邮件服务器后会有一个contentId,然后html中可以引用这个contentId显示该图片。
String contentId="1."+suffix;
//内容模板
String content="带图片的邮件img src='cid:"+contentId+"'/";
Properties prop=new Properties();
prop.setProperty("mail.host", mail_host);
prop.setProperty("mail.transport.protocol", mail_transport_protocol);
prop.setProperty("mail.smtp.auth", mail_smtp_auth);
Session session=Session.getInstance(prop);
//设置为debug模式 ,生产环境应该关掉
session.setDebug(true);
//获得transport对象
Transport ts=session.getTransport();
//连上邮件服务器
ts.connect(mail_host,port, username,password);
//创建邮件
MimeMessage message=new MimeMessage(session);
//设置发送人
message.setFrom(new InternetAddress(from));
//设置接收人
message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
//设置标题
message.setSubject(subject);
//创建正文
MimeBodyPart text=new MimeBodyPart();
//设置内容
text.setContent(content,"text/html;charset=UTF8");
//创建一个图片
MimeBodyPart image=new MimeBodyPart();
//从本地absoluteImagePath文件读取
DataHandler dh=new DataHandler(new FileDataSource(absoluteImagePath));
image.setDataHandler(dh);
//设置图片的contentId
image.setContentID(contentId);
//创建容器描述数据关系
javax.mail.internet.MimeMultipart mm=new MimeMultipart();
//容器添加内容
mm.addBodyPart(text);
//容器添加图片
mm.addBodyPart(image);
mm.setSubType("related");
message.setContent(mm);
message.saveChanges();
//存储创建的邮件
message.writeTo(new FileOutputStream("F:/imagemail.eml"));
ts.sendMessage(message, message.getAllRecipients());
ts.close();
} catch (Exception e) {
e.printStackTrace();
result=false;
}
return result;
}
//发送带附件的邮件
public static boolean sendAttachMail(String from,String to,String subject,String content,ListString absoluteFilePathList) throws Exception{
boolean result=true;
try {
Properties prop=new Properties();
prop.setProperty("mail.host", mail_host);
prop.setProperty("mail.transport.protocol", mail_transport_protocol);
prop.setProperty("mail.smtp.auth", mail_smtp_auth);
Session session=Session.getInstance(prop);
//设置为debug模式 ,生产环境应该关掉
//session.setDebug(true);
//获得transport对象
Transport ts=session.getTransport();
//连接邮件服务器
ts.connect(mail_host,port, username,password);
//创建邮件
MimeMessage message=new MimeMessage(session);
//设置发送人
message.setFrom(new InternetAddress(from));
//设置接收人
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
//设置主题
message.setSubject(subject);
//创建正文
MimeBodyPart text=new MimeBodyPart();
//设置正文内容
text.setContent(content,"text/html;charset=UTF-8");
//创建容器描述关系
MimeMultipart mp=new MimeMultipart();
//添加正文
mp.addBodyPart(text);
for(int i=0;iabsoluteFilePathList.size();i++){
//创建附件
MimeBodyPart attach=new MimeBodyPart();
DataHandler dh=new DataHandler(new FileDataSource(absoluteFilePathList.get(i)));
attach.setDataHandler(dh);
attach.setFileName(dh.getName());
//容器添加附件
mp.addBodyPart(attach);
}
mp.setSubType("mixed");
message.setContent(mp);
message.saveChanges();
//保存邮件至F盘
message.writeTo(new FileOutputStream("F:/attachMail.eml"));
ts.sendMessage(message, message.getAllRecipients());
ts.close();
} catch (Exception e) {
e.printStackTrace();
result=false;
}
return result;
}
}
有的,Java版手机邮箱-尚邮4.1.3
软件类型:国产软件
授权方式:免费软件
界面语言:简体中文
软件大小:372KB
文件类型:其它
运行环境:K-JAVA
软件等级:★★★★★
发布时间:2009-03-08
下载地址:
怎样在QQ邮箱中设置邮件账号? 1、创建电子邮件账号,其实就是填写电子邮件用户名,一般填写的用户名信息必须是在这个邮箱系统里没有被使用过的用户名,如果您填写的用户名系统显示已被注册,那么这个用户名就不...
qq邮箱用微信注册的怎么看密码 qq邮箱用微信注册的也可以按照正常步骤查看自己的密码,可以在QQ邮箱首页点击左上角的头像。在我的帐户中点击当前帐户。在帐户界面点击安全管理,然后点击独立密码。该邮箱使用...
世界十大网络黑客都有哪些人? 全球网络黑客 黑客之首“李钧涛” 黑客之二 邱俊强. 黑客之三 黄远立 黑客之四 钱嘉聪 黑客之五 吴立明 黑客之六 陈倩欢 黑客之七 许嘉怡 黑客之八 林盛隆...
中智成都签证服务有限公司电话是多少? 中智成都签证服务有限公司联系方式:公司电话028-86270434,公司邮箱ganjing@ciicsc.com,该公司在爱企查共有8条联系方式,其中有电话号码2...
苹果手机邮箱不小心删除了邮件怎么办 手机上的邮件删除以后服务器上的也删除了。1、在浏览器上访问邮箱,进入设置界面,在左侧导航窗格切换到“POP3/SMTP/IMAP”,在这里勾选“开启IMAP服务”复...
山东企业邮箱去哪申请? 企业邮箱直接在邮箱官网申请就可以,像tom企业邮箱注册流程如下所示:1.找到企业邮箱入口2.点击试用,填写提交基本信息:联系人,电话,公司名称等3.等待客户经理联系确认信息后开...