• 发送带有附件的电子邮件使用 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);

  • 相关阅读:
    关于JSON可能出现的错误,待更/todo
    mongoose的安装与使用(书签记录) 2017
    HTTP的学习记录3--HTTPS和HTTP
    HTTP的学习记录(二)头部
    HTTP(一)概述
    LeetCode 455. Assign Cookies
    LeetCode 453. Minimum Moves to Equal Array Elements
    LeetCode 448. Find All Numbers Disappeared in an Array
    LeetCode 447. Number of Boomerangs
    LeetCode 416. Partition Equal Subset Sum
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1754807.html
Copyright © 2020-2023  润新知