Use the Win2K system's CDOSYS.DLL library to send a message to an accessory

xiaoxiao2021-03-06  69

How to use the cdosys.dll Library to send an e-mail with attachmentsview products That this article applies.

THIS ARTICLE WAS Previously Published Under Q310212

SUMMARYThis 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 knower as cdosys.

More inforationto use cdosys as described in the "summary" section, Follow these Steps:

Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Under Project Types, click Visual C # Projects, and then click Console Application under Templates. By default, Class1.cs is created.Add a reference to THE Microsoft CDO for Windows 2000 Library. To do this, FOLLOW THESE STEPS:

On the Project menu, click Add Reference.On the COM tab, locate Microsoft CDO For Windows 2000 Library, and then click Select. 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.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.field;

// SET Configuration.

Adodb.field Ofield = Ofields ["http://schemas.microsoft.com/cdo/configuration/sendusing];

// Todo: to send by using the smart host, uncomment the stocking lines: //ofield.value = cdo.cdosendusing.cdosendusingport;

// of deield = Ofields ["http://schemas.microsoft.com/cdpo/configuration/smtpserver];

//ofield.value = "smarthost";

// Todo: TO Send By Using Local SMTP Service.

// of deield = 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 folload line:

//omsg.textbody = "Hello, How are you doing?";

// Todo: TO Send HTML Body, Uncomment The Following Lines:

// String Shtml;

// shtml = " / n"

// " / n"

// " Sample GIF </ Title> / N" </p> <p>// "</ hEAD> / N" </p> <p>// "<body> <p> / n" </p> <p>// "<h1> <font color = Green> Inline graphics </ font> </ h1> / n" </p> <p>// "</ body> / n" </p> <p>// "</ html>";</p> <p>//omsg.htmlbody = html;</p> <p>// TOTO: TO Send Web Page in An E-Mail, UNComment The Following Lines And make Changes in Todo Section.</p> <p>// Todo: Replace with your preferred web page</p> <p>//omsg.createmhtmlbody("http://www.microsoft.com ",</p> <p>// cdo.cdomhtmlflags.cdosuppressnone,</p> <p>// "", "");</p> <p>OMSG.SUBJECT = "Test SMTP";</p> <p>// Todo: Change the to and from address to reflect your information.</p> <p>OMSG.FROM = "someone@example.com";</p> <p>omsg.to = "someone@example.com";</p> <p>// Add attachment.</p> <p>// Todo: Change the path to the file. You Want to attach.</p> <p>OMSG.Addattachment ("c: //hello.txt", "", "");</p> <p>OMSG.Addattachment ("C: //Test.doc", "", ""); omsg.send ();</p> <p>}</p> <p>Catch (Exception E)</p> <p>{</p> <p>Console.writeline ("{0} exception caught.", E);</p> <p>}</p> <p>Return;</p> <p>}</p> <p>}</p> <p>} Where Todo APPEARS INDICATED.TO BUILD AND RUN The Program, Press F5.Verify That The e-mail message has been Both Sent and Rece some</p> <p>Referencesfor More Information About Microsoft Office Developments With Visual Studio, See The Following Microsoft Developer Network (MSDN) Web Site:</p> <p>http://msdn.microsoft.com/library/en-us/dnoffdev/html/vsofficedev.aspFor additional information about how to use CDOSYS, click the following article numbers to view the articles in the Microsoft Knowledge Base:</p> <p>310221 How to use the cdosys.dll library to Embed a message in a new message by using visual c # .net</p> <p>310224 How to use the cdosys.dll library to process mail in the drop directory by using visual c # .net</p> <p>310225 How to use the cdosys.dll library to save a message to a file by using visual c # .net</p> <p>The Information in this Article Applies TO:</p> <p>Microsoft Visual C # .NET (2003) Microsoft Visual C # .NET (2002) Microsoft Collaboration Data Objects for Windows 2000ActiveX Data Objects (ADO) 2.5ActiveX Data Objects (ADO) 2.6ActiveX Data Objects (ADO) 2.7Microsoft Internet Information Services version 6.0Microsoft Internet Information SERVICES 5.0</p> <p>Last Reviewed: 7/26/2004 (1.0) Keywords: KBCode Kbhowto KB310212 KBAUDDEVELOPER</p> <p>Microsoft LEGAL LINKS TERMS of Use Security & Privacy Accessibility</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-120356.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="120356" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.035</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '9_2B7UgoB0CoBABj4SjIh_2BBLPSfZpMuS0bS8RY7K_2BZNprYxqwNRXXLFjFct2n2_2F7FvbIuWCNsdxqsBp50Ma9cQuw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>