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

.NET郵件發送

2022-06-13   來源: Oracle 

  using System;  
 
using SystemNet;  
 
using SystemNetMail;  
 
using SystemNetMime;    
 
namespace LBCEmail  
 
{  
 
    /// <summary>  
 
    /// 發送郵件的類  
 
    /// </summary>  
 
    public class SendMail  
 
    {  
 
        private MailMessage mailMessage;  
 
        private SmtpClient smtpClient;  
 
        private string password;//發件人密碼   
 
        /// <summary>  
 
        /// 處審核後類的實例  
 
        /// </summary>  
 
        /// <param name=To>收件人地址</param>  
 
        /// <param name=From>發件人地址</param>  
 
        /// <param name=Body>郵件正文</param>  
 
        /// <param name=Title>郵件的主題</param>  
 
        /// <param name=Password>發件人密碼</param>  
 
        public SendMail(string To string From string Body string Title string Password)  
 
        {  
 
            mailMessage = new MailMessage();  
 
            mailMessageToAdd(To);  
 
            mailMessageFrom = new SystemNetMailMailAddress(From);  
 
            mailMessageSubject = Title;  
 
            mailMessageBody = Body;  
 
            mailMessageIsBodyHtml = true;  
 
            mailMessageBodyEncoding = SystemTextEncodingUTF;  
 
            mailMessagePriority = SystemNetMailMailPriorityNormal;  
 
            thispassword = Password;  
 
        }  
  
        /// <summary>  
 
        /// 添加附件  
 
        /// </summary>  
 
        public void Attachments(string Path)  
 
        {  
 
            string[] path = PathSplit();  
 
 
 
            Attachment data;  
 
            ContentDisposition disposition;  
 
 
 
            for (int i = ; i < pathLength; i++)  
 
            {  
 
                data = new Attachment(path[i] MediaTypeNamesApplicationOctet);//實例化附件  
 
                disposition = dataContentDisposition;  
 
                dispositionCreationDate = SystemIOFileGetCreationTime(path[i]);//獲取附件的創建日期  
 
                dispositionModificationDate = SystemIOFileGetLastWriteTime(path[i]);//獲取附件的修改日期  
 
                dispositionReadDate = SystemIOFileGetLastAccessTime(path[i]);//獲取附件的讀取日期  
 
                mailMessageAttachmentsAdd(data);//添加到附件中  
 
            }  
 
        }  
 
        /// <summary>  
 
        /// 異步發送郵件  
 
        /// </summary>  
 
        /// <param name=CompletedMethod></param>  
 
        public void SendAsync(SendCompletedEventHandler CompletedMethod)  
 
        {  
 
            if (mailMessage != null)  
 
            {  
 
                smtpClient = new SmtpClient();  
 
                smtpClientCredentials = new SystemNetNetworkCredential(mailMessageFromAddress password);//設置發件人身份的票據  
 
                smtpClientDeliveryMethod = SystemNetMailSmtpDeliveryMethodNetwork;  
 
                smtpClientHost = smtp + mailMessageFromHost;  
 
                smtpClientSendCompleted += new SendCompletedEventHandler(CompletedMethod);//注冊異步發送郵件完成時的事件  
 
                smtpClientSendAsync(mailMessage mailMessageBody);  
 
            }  
 
        }  

  /// <summary>  
 
        /// 發送郵件  
 
        /// </summary>  
 
        public void Send()  
 
        {  
 
            if (mailMessage != null)  
 
            {  
 
                smtpClient = new SmtpClient();  
 
                smtpClientCredentials = new SystemNetNetworkCredential(mailMessageFromAddress password);//設置發件人身份的票據  
 
                smtpClientDeliveryMethod = SystemNetMailSmtpDeliveryMethodNetwork;  
 
                smtpClientHost = smtp + mailMessageFromHost;  
 
                smtpClientSend(mailMessage);  
 
            }  
 
        }  
 
    }  
 


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