Add com reference location:
C: \ windows \ system32 \ cdosys. dll
ConsoleProgramExample:
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> // "</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. = " 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 ;
}
}
You can also save the webpage as an MHT file:
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 );