如何使用system.net.mail发送非替代多个部件

本文关键字:个部 system 何使用 net mail | 更新日期: 2023-09-27 18:36:25

我有多部分/混合正文的电子邮件,其中包含嵌套的多部分/相关部分,其中包含 Html 部分和相关图像部分。有没有办法将这些电子邮件构建为 System.Net.Mail 的 MailMessage 实例?

这不是一个替代视图问题。

  1. 多部分/混合1.1. 多部分/相关1.1.1. 文本/HTML1.1.2. 图片/动图1.2. 多部分/相关1.2.1. 文本/HTML1.2.2. 图片/动图
1.1.1

与 1.1.2 相关。但它与 1.2.2 无关。1.1.1 和 1.2.1 是单独的 HTML 正文。

我在下面粘贴了一个示例消息。

Message-ID: <mhtml-11@dsv.su.se>
Date: Wed, 04 Apr 2000 04:18:00 +0200
From: MHTML <mhtml@dsv.su.se>
MIME-Version: 1.0
To: mhtml@dsv.su.se
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: <image1.mhtml-11@dsv.su.se>
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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0ekrLhSpUmSKEdObMkSpsuY
OG/qTMnzJUWQHoMKHUq0KEagRpMqXaoUaU6dG2lKlOqRKtOkTq9q3VrV5sd/XMOKZZp1rNmz
GsuiXct2hNq2cMVmXdkzZ12LLe/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:image2.mhtml-11@dsv.su.se" 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: <image2.mhtml-11@dsv.su.se>
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
zMyZ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u6/LmVp0vDMosO7Xo4sWPCGwmfTPm4cGXF
XC0KbowZcdHLiNd6Br3YcUbIpC0vLi33H+DXbo+G3Ay7tl7atnPHxa27N1revoNXBS68uFPi
xpOLRK68OVvXHFlfpIwz81PRHrGb9ku7tOyv4Kmnbu4avvxM8RbF50T//ajs1tnVW96OWnLO
015VW9def/791fPBFx9nBPbXGH/5RXaegqHp1xloz5XEVXsFogchfueZl55oBpp2n1H2ccSc
c4BJ59GIJKZYEYoqqshiiyS+CGNzEdVo44045qhjQwEBADs=
--==boundary-1--
--==boundary-2--

如何使用system.net.mail发送非替代多个部件

您可以使用一些免费的库,请查看MailMessagesExamples.zip:http://www.lumisoft.ee/lswww/download/downloads/Examples/

或者谷歌其他一些图书馆。

Mime非常复杂,从字符串编写有效消息很难,里面有一些Unicode字符。