浏览 2588 次
锁定老帖子 主题:java 发email
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2011-02-11
package com.hua.test; import java.util.*; import javax.mail.*; import javax.mail.internet.*; /** * <p>Title: java mail</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2011</p> * <p>Company: </p> * @author hua * @version 1.0 */ public class SendMail { public SendMail() { } public void send(){ try { Properties props = new Properties(); Session sendMailSession; Store store; Transport transport; props.put("mail.smtp.auth","true"); props.put("mail.smtp.host", "smtp.sina.com"); //smtp主机名。 props.put("mail.smtp.user","doloveme70910054@sina.com"); //发送方邮件地址。 props.put("mail.smtp.password","XXXXXX"); //邮件密码。 PopupAuthenticator popA=new PopupAuthenticator();//邮件安全认证。 PasswordAuthentication pop = popA.performCheck("doloveme70910054","XXXXXX"); //填写用户名及密码 sendMailSession = Session.getInstance(props, popA); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress("doloveme70910054@sina.com")); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("doloveme70910054@sina.com")); //接收方邮件地址 newMessage.setSubject("邮件主题"); newMessage.setSentDate(new Date()); String mailContent; mailContent="你好!\n\n"; mailContent+="\t邮件正文\n\n"; mailContent+=new Date().toLocaleString(); newMessage.setText(mailContent); //邮件正文 transport = sendMailSession.getTransport("smtp"); transport.send(newMessage); } catch (MessagingException ex) { ex.printStackTrace(); } } public static void main(String[] args) { SendMail sml = new SendMail(); sml.send(); } public class PopupAuthenticator extends Authenticator{ String username=null; String password=null; public PopupAuthenticator(){} public PasswordAuthentication performCheck(String user,String pass){ username = user; password = pass; return getPasswordAuthentication(); } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-02-12
JavaMail
|
|
返回顶楼 | |
发表时间:2011-02-12
楼主你想说明什么
|
|
返回顶楼 | |
发表时间:2011-02-12
估计楼主是想展示一下自己的代码吧
|
|
返回顶楼 | |
发表时间:2011-02-12
sangmin214 写道 估计楼主是想展示一下自己的代码吧 我只是想把代码贴出来,怕以后忘了,如果有人看着恶心的话,只能请见谅 |
|
返回顶楼 | |
发表时间:2011-02-21
有发展!!!加油啊!
|
|
返回顶楼 | |