利用win2k系统的cdosys.dll库发送带附件的邮件之办法

原创 2004年09月03日 22:23:00
 

How to use the Cdosys.dll library to send an e-mail with attachments

View products that this article applies to.
This article was previously published under Q310212

SUMMARY

This article describes how to use the Collaboration Data Objects (CDO) for Windows 2000 library (Cdosys.dll) to send an e-mail message with attachments. You can send text or HTML or a Web page in the body of the e-mail message by using the local SMTP server or by using a smart host server in Microsoft Visual C# .NET.

Note The Cdosys.dll library is also known as CDOSYS.

MORE INFORMATION

To use CDOSYS as described in the "Summary" section, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. Under Project Types, click Visual C# Projects, and then click Console Application under Templates. By default, Class1.cs is created.
  4. Add a reference to the Microsoft CDO For Windows 2000 Library. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, locate Microsoft CDO For Windows 2000 Library, and then click Select.
    3. To accept your selections, click OK in the Add References dialog box.

      If you receive a dialog box to generate wrappers for the libraries that you selected, click Yes.
  5. In the code window, replace all the code with the following code:
    namespace CdoSys
    {
    	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;
    		}
    	}
    }
  6. Where TODO appears in the code, modify the code as indicated.
  7. To build and run the program, press F5.
  8. Verify that the e-mail message has been both sent and received.

REFERENCES

For more information about Microsoft Office development with Visual Studio, see the following Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/library/en-us/dnoffdev/html/vsofficedev.asp

For additional information about how to use CDOSYS, click the following article numbers to view the articles in the Microsoft Knowledge Base:

310221 How to use the Cdosys.dll library to embed a message in a new message by using Visual C# .NET

310224 How to use the Cdosys.dll library to process mail in the Drop directory by using Visual C# .NET

310225 How to use the Cdosys.dll Library to save a message to a file by using Visual C# .NET

The information in this article applies to:

  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Collaboration Data Objects for Windows 2000
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Internet Information Services version 6.0
  • Microsoft Internet Information Services 5.0
Last Reviewed: 7/26/2004 (1.0)
Keywords: kbcode kbhowto KB310212 kbAudDeveloper

Microsoft Legal Links Terms of use Security & Privacy Accessibility

IOS发送带附件的邮件

1.加入邮箱的框架 #import #import 2.添加委托 @interface ViewController : UIViewController 3.实现代码 - (v...
  • zltianhen
  • zltianhen
  • 2012-06-26 17:36:25
  • 5289

利用spring mail 发送带附件的邮件

http://pan.baidu.com/s/1mhC86NI
  • zy_281870667
  • zy_281870667
  • 2016-05-26 15:48:41
  • 3009

javamail邮件发送,带附件发送

package com.frame.util; import java.util.Date; import java.util.Enumeration; import java.util.Prope...
  • xunwei0303
  • xunwei0303
  • 2017-04-05 20:44:52
  • 712

C#中使用QQ邮箱发邮件带附件,防止附件被锁定

C#使用QQ邮箱发邮件,需要注意几点: 1. 需要现在发送者的邮箱中设置SMTP开启:在邮箱->设置->账户页 2.          public bool Sendmail(String ...
  • zpf0901
  • zpf0901
  • 2017-06-15 15:06:52
  • 707

JavaMail发送带附件的电子邮件示例

/** * CrazyItTest * 使用JavaMail发送带附件的电子邮件示例 */ package com.labci.javamail.test; import java.i...
  • tujiyue
  • tujiyue
  • 2011-05-26 21:52:00
  • 4302

java发送邮件带附件

import java.io.File; import java.util.Date; import java.util.Properties; import javax.activation.Da...
  • hfmbook
  • hfmbook
  • 2014-06-03 17:52:41
  • 10916

php 发送带附件邮件

emailclass.php
  • fdipzone
  • fdipzone
  • 2012-12-26 10:17:53
  • 17506

Java Mail---SMTP协议-Java发邮件(带附件)演示过程

转载请注明出处: http://blog.csdn.net/qq_26525215 本文源自【大学之旅_谙忆的博客】 JavaMail-API简介:邮件客户端的主要任务是向邮件服务器发送邮件,以及接收...
  • qq_26525215
  • qq_26525215
  • 2016-08-21 14:07:19
  • 3705

通过python发送带附件(支持多个附件)的邮件

目的:实现通过邮件,自动发送自动化脚本执行结果给对应的人 记录点:1 发送账号的密码设置,通过QQ发送的时候,目前QQ邮件的smtp设置的时候,都是通过授权码来进行账号认证,如果直接在脚本中写入QQ邮...
  • zhouxuan623
  • zhouxuan623
  • 2016-09-20 15:16:13
  • 3965

Python SMTP 发送带附件电子邮件

转自:http://blog.csdn.net/zm2714/article/details/7993732 可采用email模块发送电子邮件附件。发送一个未知MIME类型的文件附件其基本思路...
  • xiaosongbk
  • xiaosongbk
  • 2016-10-27 19:45:51
  • 2589
收藏助手
不良信息举报
您举报文章:利用win2k系统的cdosys.dll库发送带附件的邮件之办法
举报原因:
原因补充:

(最多只允许输入30个字)