亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1748 | 回復(fù): 0
打印 上一主題 下一主題

java 發(fā)送郵件 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-12-02 16:55 |只看該作者 |倒序瀏覽
import javax.mail.*;  import javax.mail.internet.*;  
import java.text.SimpleDateFormat;import java.util.*;  import javax.activation.*;    public class Mail {        public static void main(String[] args) {            Properties props = System.getProperties();          // 設(shè)置smtp服務(wù)器          props.setProperty("mail.smtp.host", "smtp.yicha.cn");          // 現(xiàn)在的大部分smpt都需要驗證了          props.put("mail.smtp.auth", "true");            Session s = Session.getInstance(props);          // 為了查看運行時的信息          s.setDebug(true);          // 由郵件會話新建一個消息對象          MimeMessage message = new MimeMessage(s);          try {              // 發(fā)件人              InternetAddress from = new InternetAddress("lgzbj2006@yahoo.com.cn");              //message.setFrom(from);              // 收件人              InternetAddress to = new InternetAddress("renyiyong@yicha.cn");              InternetAddress to2 = new InternetAddress("liuhongwei@yicha.cn");            InternetAddress[] totest={to,to2};            //message.setRecipient(Message.RecipientType.TO, to);              message.setRecipients(Message.RecipientType.TO,totest);            // 郵件標(biāo)題              message.setSubject("test");              String content = "測試內(nèi)容";              // 郵件內(nèi)容,也可以使純文本"text/plain"              message.setContent(content, "text/html;charset=GBK");              message.getReceivedDate();              /****下面代碼是發(fā)送附件****** */             String fileName = "d:\\hello.txt";             MimeBodyPart messageBodyPart = new MimeBodyPart();             SimpleDateFormat stringdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss E");            messageBodyPart.setText("問答元搜索,解析百度頁面出現(xiàn)問題,請及時處理\r\n"+"yicha.cn\r\n"+stringdate.format(new Date()));             Multipart multipart = new MimeMultipart();             multipart.addBodyPart(messageBodyPart);              messageBodyPart = new MimeBodyPart();             DataSource source = new FileDataSource(fileName);             messageBodyPart.setDataHandler(new DataHandler(source));             messageBodyPart.setFileName(fileName);             multipart.addBodyPart(messageBodyPart);              message.setContent(multipart);                           message.saveChanges();              Transport transport = s.getTransport("smtp");              // smtp驗證,就是你用來發(fā)郵件的郵箱用戶名密碼              transport.connect("smtp.yicha.cn", "renyiyong@yicha.cn", "yicha1");              // 發(fā)送              transport.sendMessage(message, message.getAllRecipients());              transport.close();            } catch (Exception e) {              e.printStackTrace();          }        }    }  需要兩個jar包的下載地址:mail.jar 下載地址:
http://java.sun.com/products/javamail/downloads/index.html
activation.jar 下載地址:
http://java.sun.com/products/javabeans/jaf/downloads/index.html
               
               
               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u3/104127/showart_2109617.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP