1
我有多部分/混合體的郵件包含嵌套的多部分/相關部分與Html部分和相關的圖像部分。有沒有辦法將這些電子郵件構建爲System.Net.Mail的MailMessage實例?如何使用system.net.mail發送非替代性的多個部分
這不是一個備用查詢問題。
- multipart/mixed 1.1。多部分/相關 1.1.1。 text/html 1.1.2。圖片/ gif 1.2。多部分/相關 1.2.1。 text/html 1.2.2。 image/gif
1.1.1與1.1.2相關。但它與1.2.2無關。 1.1.1和1.2.1是獨立的html實體。
我在下面粘貼了一條示例消息。
Message-ID: <[email protected]>
Date: Wed, 04 Apr 2000 04:18:00 +0200
From: MHTML <[email protected]>
MIME-Version: 1.0
To: [email protected]
Subject: Test message no. 11
Content-Type: multipart/mixed; boundary="==boundary-2"
--==boundary-2
Content-Type: multipart/related; boundary="==boundary-1"; type="text/html"
Content-Location: http://www.dsv.su.se/jpalme/mimetest/
Text displayed only to non-MIME-compliant mailers
--==boundary-1
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD><TITLE>Test message no. 11 first part</TITLE>
</HEAD>
<BODY>
<H1>This is test message no. 11 first HTML part</H1>
<H2>Here comes the red test image:</H2>
<IMG SRC="http://www.dsv.su.se/jpalme/mimetest/red-test-image.gif"
BORDER=0 HEIGHT=32 WIDTH=117 ALT="red test image">
<P>This is the last line of this test message.
</BODY></HTML>
--==boundary-1
Content-Type: image/gif
Content-ID: <[email protected]>
Content-Location: http://www.dsv.su.se/jpalme/mimetest/red-test-image.gif
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="red-test-image.gif"
R0lGODlhdQAgAPcAAP//////zP//mf//Zv//M///AP/M///MzP/Mmf/MZv/MM//MAP+Z//+Z
zP+Zmf+ZZv+ZM/+ZAP9m//9mzP9mmf9mZv9mM/9mAP8z//8zzP8zmf8zZv8zM/8zAP8A//8A
zP8Amf8AZv8AM/8AAMz//8z/zMz/mcz/Zsz/M8z/AMzM/8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suiXct2hNq2cMVmXdkzZ12LLe/ehYrXpsy/MPUGHvw04lzCdhFbzasYMd+aUxsnnrzTq1uw
cTN3tVrxrebPWDGDHr3UM+nTHE2jXn1RNevXEl3Dfi179urDJrte5BzVcknNhyNHZiyzJnGv
uWMuppu7uHLkyV1Kxe1ccOGZ0Cn/xshcu8/K2g2LQ8bJGPJj4eh3+/WNHb118PAtBn8aXTrn
6s7tl2QP9b399fhNN55tbe31FYEITlRbgqAtyCBwAz5I20MUVmjhhRgyFBAAOw==
--==boundary-1--
--==boundary-2
Content-Type: multipart/related; boundary="==boundary-1"; type="text/html"
Content-Location: http://www.dsv.su.se/jpalme/mimetest/
Text displayed only to non-MIME-compliant mailers
--==boundary-1
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD><TITLE>Test message no. 11 second part</TITLE>
</HEAD>
<BODY>
<H1>This is test message no. 11 second HTML part</H1>
<H2>Here comes the yellow test image:</H2>
<IMG SRC="cid:[email protected]" BORDER=0 HEIGHT=32 WIDTH=152
ALT="yellow test image">
<P>This is the last line of this test message.
</BODY></HTML>
--==boundary-1
Content-Type: image/gif
Content-ID: <[email protected]>
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="yellow-test-image.gif"
R0lGODlhmAAgAPcAAP//////zP//mf//Zv//M///AP/M///MzP/Mmf/MZv/MM//MAP+Z//+Z
zP+Zmf+ZZv+ZM/+ZAP9m//9mzP9mmf9mZv9mM/9mAP8z//8zzP8zmf8zZv8zM/8zAP8A//8A
zP8Amf8AZv8AM/8AAMz//8z/zMz/mcz/Zsz/M8z/AMzM/8zMzMzMmczMZszMM8zMAMyZ/8yZ
zMyZmcyZZsyZM8yZAMxm/8xmzMxmmcxmZsxmM8xmAMwz/8wzzMwzmcwzZswzM8wzAMwA/8wA
zMwAmcwAZswAM8wAAJn//5n/zJn/mZn/Zpn/M5n/AJnM/5nMzJnMm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z81PRHrGb9ku7tOyv4Kmnbu4avvxM8RbF50T//ajs1tnVW96OWnLO
015VW9def/791fPBFx9nBPbXGH/5RXaegqHp1xloz5XEVXsFogchfueZl55oBpp2n1H2ccSc
c4BJ59GIJKZYEYoqqshiiyS+CGNzEdVo44045qhjQwEBADs=
--==boundary-1--
--==boundary-2--
我知道lumisoft的庫。我看過像MimeKit這樣的其他開源軟件。由於我的要求,我不得不開發自己的解析器。如果我能解決上述問題,那將是完美的。 –
我看不到MailMessage將允許解析或構建複雜的消息,所以你不能這樣做。爲什麼你需要這麼拼命MailMessage?那你爲什麼不做自己的課?如果您需要SmtpClient類,那麼這是一個問題,但如果使用一些免費的可用庫,則您可以編寫自己的SMTP客戶端。 – user2959922