How to send cdo email from C#

The Microsoft .NET framework includes two namespaces, namely System.Net and System.Net.Sockets, which provide a managed implementation of Internet protocols. These namespaces allow applications to send or receive data over the Internet.

Cdosys.dll library

In the previous C# program, we learned how to send an email with a text body using the SMTP (Simple Mail Transfer Protocol). However, in this scenario, we are sending an email without using the SMTP protocol through C# programming. Instead of SMTP, we will be utilizing CDOSYS (Collaboration Data Objects for Windows 2000 library) for this purpose. CDOSYS is also known as Cdosys.dll, which is a library that provides functionality for sending emails.

By using the Cdosys.dll library, we can send emails directly from our C# program without relying on the SMTP protocol. This library offers a different approach to email sending and provides additional features and flexibility for customizing the email content and format.

Create a new C# project and add a reference to Microsoft CDO For Windows 2000 Library . From the following picture you can understand how to add Microsoft CDO For Windows 2000 Library in your C# project.

csharp-cdo Full Source C#
using System; using System.Windows.Forms; using System.Net.Mail; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { CDO.Message oMsg = new CDO.Message(); CDO.IConfiguration iConfg; iConfg = oMsg.Configuration; ADODB.Fields oFields; oFields = iConfg.Fields; ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"]; oFields.Update(); oMsg.Subject = "Test CDO"; oMsg.From = "from_address"; oMsg.To = "to_address"; oMsg.TextBody = "CDO Mail test"; oMsg.Send(); MessageBox.Show("mail Send"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } }

Conclusion

Exploring the CDOSYS library and understanding its usage in C# programming, you can explore alternative methods for sending emails and leverage the specific features and capabilities it offers.