Net-informations.com
SiteMap  | About    

How to send cdo email from C#

The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets for managed implementation of Internet protocols that applications can use to send or receive data over the Internet .

In the previous C# program SMTP email from C# describes how to send an email with text body . Here we are sending an email without using SMTP protocol through C# programming . Instead of SMTP here we use CDOSYS , Collaboration Data Objects (CDO) for Windows 2000 library (Cdosys.dll) . The Cdosys.dll library is also known as CDOSYS .

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



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());
            }
        }
    }
}




net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.