发送带有附件的电子邮件使用 Cdosys.dll 库

增加 COM 引用 位置:

C:\WINDOWS\System32\cdosys.dll

控制台程序的例子如下:

using  System;
    
class  Class1
    {
        
static   void  Main( string [] args)
        {
            
try  
            {            
                CDO.Message oMsg 
=   new  CDO.Message();
                CDO.IConfiguration iConfg; 

                iConfg 
=  oMsg.Configuration;

                ADODB.Fields oFields;
                oFields 
=  iConfg.Fields;       

                
//  Set configuration.
                ADODB.Field oField  =  oFields[ " http://schemas.microsoft.com/cdo/configuration/sendusing " ];
                        
                
// TODO: To send by using the smart host, uncomment the following lines:
                
// oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
                
// oField = oFields[" http://schemas.microsoft.com/cdo/configuration/smtpserver "];
                
// oField.Value = "smarthost";

                
//  TODO: To send by using local SMTP service. 
                
// oField = oFields[" http://schemas.microsoft.com/cdo/configuration/sendusing "];
                
// oField.Value = 1;  

                oFields.Update();

                
//  Set common properties from message.

                
// TODO: To send text body, uncomment the following line: 
                
// oMsg.TextBody = "Hello, how are you doing?";
            

                
// TODO: To send HTML body, uncomment the following lines:
                
// String sHtml;
                
// sHtml = "<HTML>\n" + 
                
//     "<HEAD>\n" +
                
//     "<TITLE>Sample GIF</TITLE>\n" +
                
//     "</HEAD>\n" +
                
//     "<BODY><P>\n" + 
                
//     "<h1><Font Color=Green>Inline graphics</Font></h1>\n" +
                
//     "</BODY>\n" + 
                
//     "</HTML>";
                
// oMsg.HTMLBody = sHtml;

                
// TOTO: To send WEb page in an e-mail, uncomment the following lines and make changes in TODO section.
                
// TODO: Replace with your preferred Web page
                
// oMsg.CreateMHTMLBody(" http://www.microsoft.com ",
                
//     CDO.CdoMHTMLFlags.cdoSuppressNone, 
                
//     "", ""); 
                oMsg.Subject  =   " Test SMTP " ;  

                
// TODO: Change the To and From address to reflect your information.                       
                oMsg.From  =   " someone@example.com " ;
                oMsg.To 
=   " someone@example.com " ;
                
// ADD attachment.
                
// TODO: Change the path to the file that you want to attach.
                oMsg.AddAttachment( " C:\\Hello.txt " "" "" );
                oMsg.AddAttachment(
" C:\\Test.doc " "" "" );
                                    oMsg.Send();
            }
            
catch  (Exception e)
            {
                Console.WriteLine(
" {0} Exception caught. " , e);
            }
            
return ;
        }
    }


也可以保存网页为mht文件:

   CDO.Message msg = new CDO.MessageClass();
            CDO.Configuration cfg = new CDO.ConfigurationClass();
           
            msg.Configuration = cfg;
            msg.CreateMHTMLBody("http://www.sina.com.cn", CDO.CdoMHTMLFlags.cdoSuppressAll, "", "");

            msg.GetStream().SaveToFile("c:\\a.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

 

 

 

转载于:https://www.cnblogs.com/chenqingwei/archive/2010/06/09/1754807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值