然後看看我們的前台代碼
using System;
using System
Data;
using System
Configuration;
using System
Web;
using System
Web
Security;
using System
Web
UI;
using System
Web
UI
WebControls;
using System
Web
UI
WebControls
WebParts;
using System
Web
UI
HtmlControls;
using System
Net
Mail;
using STS
MailSystem
Common;
using System
Text;
public partial class _Default : System
Web
UI
Page
{
protected void Page_Load(object sender
EventArgs e)
{
}
protected void Button
_Click(object sender
EventArgs e)
{
QMail mail = new QMail();
Attachment attachment = null;
//File Name
string fileName = string
Empty;
string filePath = string
Empty;
StringBuilder mailBody = new StringBuilder();
//mailBody
Append(
content
type:base
);
//mailBody
Append(
content
transfer
encodinf:
);
//mailBody
Append(
content
disposition:inline
);
//mailBody
Append(
filename:aa
);
//增加附件
//這裡指去考慮附件是圖片的情況
//其他情況不考慮
if (File
Value !=
)
{
filePath = this
File
PostedFile
FileName;
fileName = filePath
Substring(filePath
LastIndexOf(
\\
) +
);
//增加顯示圖片
mailBody
Append(
content
id:
+ fileName);
mailBody
Append(
<img src=
cid:
+ fileName+
/>
);
attachment = new Attachment(filePath);
}
//Send Mail
mail
MailSend(
minqiang
zhang@metinform
cn
minqiang
zhang@metinform
cn
minqiang
zhang@metinform
cn
演示如果在正文顯示附件
mailBody
ToString()
attachment
);
}
}
寫完之後點擊發送我靠!真的可以也
代碼其實很簡單我們來總結一下:
這裡最重要的東西是在正文中如何使用Img顯示附件中的圖片從代碼中我們可以看到contentid:附件中圖片名字的方案解決的
以上是自己方法如果誰有更好的方法請貼出來大家共享!
聲明:由於代碼是簡單測試是否可以在附件中顯示附件所以代碼寫的很亂大家看思路就行了
[] []
From:http://tw.wingwit.com/Article/program/net/201311/15343.html