Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Send mail using CDO.Message

Some time we have requirement that we have to send a mail without SMTP information or On Server SMTP is now allowed or install. Then we may send mail using CDO instead of SMTP server. For send the mail using CDO, we have to add reference of Microsoft CDO for Windows 2000 Library. Please check the steps. (1) Add reference for "Microsoft CDO for Windows 2000 Library" Check image.

Adding reference of CDO In asp.net


Now there will be two references for:

Interop.ADODB.dll
Interop.CDO.dll (2) Create CDO.Message object
(3)Create attribute for CDO.IConfiguration
(4) Check the connfiguration
(5) Add ADODB Fields (for send using)
(6) Now update the field information means there is no more field
(7) Now add Subject, From, To Information, HTML Body
(8) Yippy I love this line always "SendMail" with message object.

Now on button click write the below code on button click:

IN C#.net

            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 = "Rohit.kakhria@pugmarks.com";
            oMsg.To = "kakriarohit@gmail.com";
            //oMsg.TextBody = "CDO Mail test";
            oMsg.HTMLBody = "CDO Mail test";
            oMsg.Send();
            Response.Write("Mail Sent");

in VB.Net

Dim oMsg As New CDO.Message()
Dim iConfg As CDO.IConfiguration
iConfg = oMsg.Configuration
Dim oFields As ADODB.Fields
oFields = iConfg.Fields
Dim oField As ADODB.Field = oFields("http://schemas.
                            microsoft.com/cdo/configuration/sendusing")
oFields.Update()
oMsg.Subject = "Test CDO"
oMsg.From = "Rohit.kakhria@pugmarks.com"
oMsg.[To] = "kakriarohit@gmail.com"
'oMsg.TextBody = "CDO Mail test";
oMsg.HTMLBody = "CDO Mail test"
oMsg.Send()
Response.Write("Mail Sent")

Share this article   |    Print    |    Article read by 13722 times
Author:
Rohit kakria
I am software developer, moderator of xpode.com
Related Articles: No related article
Related Interview Questions: No related interview question