熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET如何在mail的正文顯示圖片[2]

2013-11-13 11:11:16  來源: .NET編程 

  然後看看我們的前台代碼

 using System;
 using SystemData;
 using SystemConfiguration;
 using SystemWeb;
 using SystemWebSecurity;
 using SystemWebUI;
 using SystemWebUIWebControls;
 using SystemWebUIWebControlsWebParts;
 using SystemWebUIHtmlControls;
using SystemNetMail;
using STSMailSystemCommon;
using SystemText;

    public partial class _Default : SystemWebUIPage
    {
        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 = stringEmpty;
            string filePath = stringEmpty;
            StringBuilder mailBody = new StringBuilder();
            //mailBodyAppend(contenttype:base);
            //mailBodyAppend(contenttransferencodinf:);
            //mailBodyAppend(contentdisposition:inline);
            //mailBodyAppend(filename:aa);
            //增加附件
            //這裡指去考慮附件是圖片的情況
            //其他情況不考慮
            if (FileValue != )
            {
                filePath = thisFilePostedFileFileName;
                fileName = filePathSubstring(filePathLastIndexOf(\\) + );
                //增加顯示圖片
                mailBodyAppend(contentid: + fileName);
                mailBodyAppend(<img src=cid: + fileName+ />);
                attachment = new Attachment(filePath);             
            }        


            //Send Mail
            mailMailSend(minqiangzhang@metinformcn minqiangzhang@metinformcn
                minqiangzhang@metinformcn 演示如果在正文顯示附件 mailBodyToString() attachment );

        }
    }


  寫完之後點擊發送我靠!真的可以也

  代碼其實很簡單我們來總結一下:

  這裡最重要的東西是在正文中如何使用Img顯示附件中的圖片從代碼中我們可以看到contentid:附件中圖片名字的方案解決的

  以上是自己方法如果誰有更好的方法請貼出來大家共享!

  聲明:由於代碼是簡單測試是否可以在附件中顯示附件所以代碼寫的很亂大家看思路就行了

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15343.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.