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

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

2022-06-13   來源: .NET編程 

  最近看到很多人在問這個問題就是如何在Mail的正文中如何顯示附件的圖片本人也不會就去網上搜索可是網上竟然沒有(可能是太簡單很多人不屑提供代碼)於是本人就嘗試

  最先想到的就是outLook可以顯示附件中的圖片於是在OutLook的郵件正文:右鍵>ViewSource 就看到了

<img width= height= id=_x_i
src=cid:imagejpg@CCAFCEED>

  這種代碼 所以產生的第一個想法就是在寫正文的時候自動根據附件去生成類似代碼說干就干馬上動手!

  新建一個網站拖幾個FileUpload 上去如下圖

  根據MicroSoft自帶的SystemNetMail 組件完成發送方法代碼如下

  using System;
 using SystemCollectionsGeneric;
 using SystemText;
 using SystemNetMail;
 using SystemNet;
 using SystemIO;
 namespace STSMailSystemCommon
 {
     public class QMail
    {
        /**//// <summary>
        /// 描述:Email發送通用函數
        /// </summary>
        /// <param name=from>發件人</param>
        /// <param name=to>收件人(多個收件人以逗號隔開)</param>
        /// <param name=subject>主題</param>
        /// <param name=text>內容</param>
        /// <param name=attch>附件</param>
        /// <returns></returns>
        public string MailSend(string from string to string cc string subject string text Attachment attch string priority)
        {
            MailMessage message = new MailMessage(from to);
            messageCCAdd(cc);
            messageSubject = subject;
            messageBody = text;
           

            //messageCCAdd(new MailAddress(from)); //超送給自己
            //messageBccAdd(new MailAddress());

            if (attch != null)
            {
                Attachment data = attch;
                messageAttachmentsAdd(data);
            }

            messageBodyEncoding = SystemTextEncodingUTF;//編碼方式
            switch (priorityToUpper())
            {
                case HIGH:
                    messagePriority = MailPriorityHigh;//優先級
                    break;
                case NORMAL:
                    messagePriority = MailPriorityNormal;//優先級
                    break;
                case LOW:
                    messagePriority = MailPriorityLow;//優先級
                    break;
                default:
                    messagePriority = MailPriorityNormal;//優先級
                    break;
            }
           
            messageIsBodyHtml = true;//是否是html格式
            SmtpClient client = new SmtpClient();//不同情況更改

            //clientCredentials = CredentialCacheDefaultNetworkCredentials;//匿名認證
           
           
            try
            {
                clientSend(message);
                return ;
            }
            catch (Exception e)
            {
               
                return eMessage;
            }
           
        }

       

    }
}


[]  []  


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