Hotmail 不提供標準 POP3 存取,但 Outlook Express 可直接連線,其使用HTTPMail 協議(基於 WebDAV 的 HTTP/1.1 擴展)。本文為系列第一部分,示範 C# 透過 MSXML2.XMLHTTP 連線 Hotmail、取得收件箱/發件箱 URL。
https://services.msn.com/svcs/hotmail/httpmail.aspXMLHTTP 元件自動處理:重導向、負載平衡、Cookie、驗證交握<?xml version="1.0"?>
<D:propfind xmlns:D="DAV:" xmlns:h="https://schemas.microsoft.com/hotmail/" xmlns:hm="urn:schemas:httpmail:">
<D:prop>
<h:adbar/> <!-- 廣告列 -->
<hm:contacts/> <!-- 通訊錄 -->
<hm:inbox/> <!-- 收件箱 -->
<hm:outbox/> <!-- 發件箱 -->
<hm:sendmsg/> <!-- 發送郵件端點 -->
<hm:sentitems/> <!-- 已寄出 -->
<hm:deleteditems/> <!-- 刪除項目 -->
<hm:drafts/> <!-- 草稿 -->
<hm:msgfolderroot/> <!-- 根資料夾 -->
<h:maxpoll/> <!-- 最大輪詢間隔 -->
<h:sig/> <!-- 簽名 -->
</D:prop>
</D:propfind>
using MSXML2; // 參考 Microsoft XML, v6.0
XMLHTTP xmlHttp = new XMLHTTP();
string serverUrl = "https://services.msn.com/svcs/hotmail/httpmail.asp";
string username = "your@hotmail.com";
string password = "yourpassword";
string query = "..."; // 上方 XML
// 同步請求(false),提供帳密進行基本驗證
xmlHttp.open("PROPFIND", serverUrl, false, username, password);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.send(query);
string responseXml = xmlHttp.responseText;
open 最後兩參數提供帳密,避免彈出登入對話框false = 同步阻塞,適合主控台/服務;GUI 應用建議 true 非同步XMLHTTP 自動處理 302 重導向、Cookie、驗證挑戰<?xml version="1.0" encoding="Windows-1252"?>
<D:multistatus>
<D:response>
<D:propstat>
<D:prop>
<hm:inbox>https://law15.oe.hotmail.com/.../Inbox/</hm:inbox>
<hm:sendmsg>https://law15.oe.hotmail.com/.../SendMsg/</hm:sendmsg>
<hm:sentitems>https://.../SentItems/</hm:sentitems>
<hm:deleteditems>https://.../DeletedItems/</hm:deleteditems>
<hm:msgfolderroot>https://.../</hm:msgfolderroot>
</D:prop>
</D:propstat>
</D:response>
</D:multistatus>
string inboxUrl = null, sendUrl = null;
using (var reader = new StringReader(responseXml))
using (var xml = new XmlTextReader(reader))
{
while (xml.Read())
{
if (xml.NodeType == XmlNodeType.Element)
{
string name = xml.Name;
if (name == "hm:inbox" || name == "hm:sendmsg")
{
xml.Read(); // 移到文字內容
if (name == "hm:inbox") inboxUrl = xml.Value;
else if (name == "hm:sendmsg") sendUrl = xml.Value;
}
}
}
}
Console.WriteLine($"Inbox: {inboxUrl}");
Console.WriteLine($"SendMsg: {sendUrl}");
public class HotmailClient
{
private XMLHTTP _xmlHttp = new XMLHTTP();
private string _inboxUrl, _sendUrl;
public void Connect(string username, string password)
{
string serverUrl = "https://services.msn.com/svcs/hotmail/httpmail.asp";
string query = BuildFolderQuery();
_xmlHttp.open("PROPFIND", serverUrl, false, username, password);
_xmlHttp.setRequestHeader("Content-Type", "text/xml");
_xmlHttp.send(query);
ParseFolderResponse(_xmlHttp.responseText);
}
private string BuildFolderQuery() { /* 返回上方 XML 字串 */ }
private void ParseFolderResponse(string xml) { /* 上方解析邏輯 */ }
public string InboxUrl => _inboxUrl;
public string SendUrl => _sendUrl;
}
services.msn.com 及熱導向後的伺服器| 風險 | 說明 | 建議 |
|---|---|---|
| 明文密碼 | 基本驗證傳輸 Base64 編碼密碼 | 務必使用 HTTPS(舊閘道可能不支援) | 協議非公開 | HTTPMail 無官方文件,隨時可能變更 | 遷移至 Microsoft Graph API / IMAP |
| XMLHTTP 元件 | COM 元件,需註冊、32/64 位元相容性 | 改用 HttpClient + 手動 WebDAV 實作 |
第一步核心成果:取得 _inboxUrl(收件箱)與 _sendUrl(發送端點)。後續操作(列舉郵件、接收、發送)均依賴這兩個 URL。理解 HTTPMail = WebDAV + Hotmail 擴展,是整合舊系統的關鍵。