Using CDO;
Using System; Namespace ConsoleApp1 {class Program {static void Main (string[] args) {string from
= "XXX";
string to = "xxx";
String userName = from;
string password = "xxx";
string title = "Test Message";
String BODY = "Hello, how are you doing?";
String server = "Smtp.126.com"; int port = 25;
SSL 465 try {SendEmail (from, to, title, body, password, server, port, false);
Console.WriteLine ("Send Complete");
catch (Exception) {throw new Exception ();
} console.readkey (); public static bool SendEmail (string from, string to, string title, string body, string password, string server
, int port, BOOL SSL) {BOOL flag = false; try {#region MessaGE omsg = new message ();
var conf = omsg.configuration; var ofields = conf.
Fields; ofields["Http://schemas.microsoft.com/cdo/configuration/sendusing"].
Value = Cdosendusing.cdosendusingport; ofields["Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].
Value = Cdoprotocolsauthentication.cdobasic; if (SSL) {ofields["Http://schemas.microsoft.com/cdo/configuration/smtpusessl"].
Value = true; } ofields["Http://schemas.microsoft.com/cdo/configuration/smtpserver"]. Value = server;//must be filled in, and the ofields["Http://schemas.microsoft.com/cdo/configuration/smtpserverport" can be used for real. Value = port;//Mailbox Port ofields["Http://schemas.microsoft.com/cdo/configuration/sendemailaddress"]. Value = from;//Sender mailbox ofields["Http://schemas.microsoft.com/cdo/configuration/sendusername"].
Value = from;//Mailbox Sender Name ofields["Http://schemas.microsoft.com/cdo/configuration/sendpassword"]. Value = password;
e-mail sender password, must be true ofields.update ();
omsg.configuration = conf; oMsg.Subject = title;//Theme omsg.htmlbody = body;//message body oMsg.From = fr
om;//Sender omsg.to = to;//receiver Omsg.send ();//Send flag = true;
#endregion} catch (Exception) {flag = false;
throw new Exception ();
return flag;
}
}
}