2009年3月22日 星期日

[Practice] Photoshop CS - Practice

Library Life


NCKU




Lorry


Purple Style


Rock

Blog Style

2009年3月19日 星期四

[Skill][轉]Word 檔以每一頁另存的方法

Question:
請問一下,如果有一個WORD檔,總共有47頁,請問我要如何讓這47頁,每一頁另存新檔呢?那如果二頁另存一個檔呢?可以嗎?或如果有一些要三頁一個檔,有一些要四頁一個檔也可以嗎?要用什麼方法呢?今天老闆問我的問題。

Answer:

在 Microsoft 官方技術支援網頁中,有這樣的 Word VBA 「儲存每個頁(逐頁)或節的文件為另一個檔案」,請逕自前往以下網址參閱:
http://support.microsoft.com/kb/306348/zh-tw?spid=3253&sid=251

[REF]http://blog.yam.com/trump/article/12516833

2009年3月7日 星期六

[轉][Java]Gmail- POP3 & SMTP

Gmail目前已經啟用了POP3和SMTP服務,
與其他郵箱不同的是Gmail提供的POP3和SMTP是使用安全套接字層SSL的,
因此常規的JavaMail程序是無法收發郵件的,
下面是使用JavaMail如何收取Gmail郵件以及發送郵件的代碼:

1. 郵件收取

import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

/**
* 用於收取Gmail郵件
* @author Winter Lau
*/
public class GmailFetch {

public static void main(String argv[]) throws Exception {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "995");
props.setProperty("mail.pop3.socketFactory.port", "995");

//以下步驟跟一般的JavaMail操作相同
Session session = Session.getDefaultInstance(props,null);

//請將紅色部分對應替換成你的郵箱帳號和密碼
URLName urln = new URLName("pop3","pop.gmail.com",995,null,
"[郵箱帳號]", "[郵箱密碼]");
Store store = session.getStore(urln);
Folder inbox = null;
try {
store.connect();
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
System.out.println("收件箱的郵件數:" + messages.length);
for (int i = 0; i < messages.length; i++) {
//郵件發送者
String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);
System.out.println("FROM:" + ia.getPersonal()+'('+ia.getAddress()+')');
//郵件標題
System.out.println("TITLE:" + messages[i].getSubject());
//郵件大小
System.out.println("SIZE:" + messages[i].getSize());
//郵件發送時間
System.out.println("DATE:" + messages[i].getSentDate());
}
} finally {
try {
inbox.close(false);
} catch (Exception e) {}
try {
store.close();
} catch (Exception e) {}
}
}

protected static String decodeText(String text)
throws UnsupportedEncodingException {
if (text == null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO8859_1"));
return text;
}
}


2. 發送郵件

import java.security.Security;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
* 使用Gmail發送郵件
* @author Winter Lau
*/
public class GmailSender {

public static void main(String[] args) throws AddressException, MessagingException {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
final String username = "[郵箱帳號]";
final String password = "[郵箱密碼]";
Session session = Session.getDefaultInstance(props, new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});

// -- Create a new message --
Message msg = new MimeMessage(session);

// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(username + "@mo168.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[收件人地址]",false));
msg.setSubject("Hello");
msg.setText("How are you");
msg.setSentDate(new Date());
Transport.send(msg);

System.out.println("Message sent.");
}
}


[REF]:http://balafish.blogspot.com/2007/10/javamailgmailssl.html

2008年12月18日 星期四

[Skill][轉]IMAP與POP之特性與優缺


IMAP與POP比較

IMAP(Internet Message Access Protocol)定義:
IMAP為一收取電子郵件的標準協定,屬於客戶-伺服(Client-Server)之協定;伺服器依此協定,替客戶端使用者收取並儲存郵件。使用者可以僅檢視郵件之發送者及標題,並決定是否下載該郵件。使用者亦可在伺服器上建立並操作檔案夾(folder)或信箱、刪除郵件等。

POP(Post Office Protocol)定義:
POP為另一較不複雜的接收電子郵件之標準協定,亦屬一客戶-伺服協定,伺服器依此協定替客戶端的使用者收取並暫存郵件,當使用者檢查在伺服器上的郵件信箱時,即下載郵件。

IMAP優勢:
1.開啟信箱時,只是下載信頭(message headers)部分而已,故不會佔用PC端的硬碟空間。
2.可以從數個不同的地點連線,所讀取的信件仍為同一份置於伺服器上的信箱。
3.不必一直收信,信箱會自動更新。當網路速度受限時,performance 會較POP server好,因為只
 是下載信頭部分而已。
4.以檔案夾(folder)的方式管理信件較方便。

POP弱勢:
1.通常開啟信箱之後,信件即全部被下載儲存於PC上,佔用PC上的硬碟空空間;而伺服器上並不
 保留信件備份,以免信件一直累積,造成伺服器上的信箱爆滿。因此需自行指定是否需要儲存信
 件於伺服器上。
2.從不同的地點連線時,無法使各地點所擁有的信箱均一致同步,出現在(A)PC上的信件,便不再
 出現於(B)PC上;因此當連線時,為了要達到同步化,便會一再下載信件,導致信件重複出現。
3.必須手動收信,信箱不會自動更新。當網路速度受限時,performance 則會較差。
4.從不同的地點連線時,無法讀取到所有的檔案夾,管理上較差。


結論:
在使用者郵件之管理上,IMAP顯然較具有方便性。像現在gmail開放IMAPi功能了,讓使用者可以真正的在自己電腦上「收發Gmail」─只要你的郵件軟體支援,在這個模式下,使用者可以直接在線上讀信、回信、留草稿、砍信,而不需要把整個信箱搬回家。在你工作的同時,Gmail也會記錄你的所有動作,當你回到網頁時,信箱的狀態就跟在你的電腦上一樣的熟悉親切。甚至Gmail特有的標籤功能,也會被模擬成IMAP中的「資料夾」,並擁有同樣的運用彈性。

[REF]http://blog.sina.com.tw/ghost/article.php?pbgid=17542&entryid=578545

[Song]James Blunt

James Blunt - Give Me Some Love



James Blunt - Tears And Rain

2008年12月5日 星期五

[Java IDE]當 netbean 遇到 Java Heap Space

當 netbean 遇到 Java Heap Space

解決方法:
http://docs.google.com/fileview?id=F.c9a97ec6-c3ad-4a59-b890-0df5019fd611&hl=en