Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
oorspronkelijk KB-nummer: 310212
In dit artikel wordt beschreven hoe u de CDO -bibliotheek (Collaboration Data Objects) voor Windows 2000 (Cdosys.dll) gebruikt om een e-mailbericht met bijlagen te verzenden. U kunt tekst of HTML of een webpagina in de hoofdtekst van het e-mailbericht verzenden met behulp van de lokale SMTP-server of met behulp van een slimme hostserver in Microsoft Visual C#.
Notitie
De Cdosys.dll bibliotheek wordt ook wel CDOSYS genoemd.
Als u CDOSYS wilt gebruiken zoals beschreven in de sectie Samenvatting, voert u de volgende stappen uit:
Start Microsoft Visual Studio.
Selecteer in het menu BestandNieuween selecteer vervolgens Project.
Selecteer onder ProjecttypenVisual C#en selecteer vervolgens Consoletoepassing onder Sjablonen. Standaard wordt Program.cs gemaakt.
Notitie
In Microsoft Visual C# .NET 2003 wordt Visual C# gewijzigd in Visual C#-projecten. Standaard wordt Class1.cs gemaakt.
Voeg een verwijzing toe naar de Microsoft CDO voor Windows 2000 Library. Voer hiervoor de volgende stappen uit:
Selecteer in het menu Project de optie Verwijzing toevoegen .
Zoek op het tabblad COMMicrosoft CDO voor Windows 2000 Library.
Notitie
Selecteer in Visual C# .NET 2003 Selecteer.
Als u uw selecties wilt accepteren, selecteert u OK- in het dialoogvenster Verwijzingen toevoegen.
Als u een dialoogvenster ontvangt om wrappers te genereren voor de bibliotheken die u hebt geselecteerd, selecteert u Ja.
Vervang in het codevenster alle code door de volgende 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; } } }
Wijzig de code zoals aangegeven, waar TODO in de code wordt weergegeven.
Druk op F5 om het programma te bouwen en uit te voeren.
Controleer of het e-mailbericht is verzonden en ontvangen.
Zie Microsoft Office-ontwikkeling met Visual Studiovoor meer informatie over Microsoft Office-ontwikkeling met Visual Studio.