Hi Friends,
Recently I have been searching for an API which can send emails through SSL enabled servers like gmail.com in ASP.NET. For this purpose, ASP.NET is already having two API's : System.Web.Mail and System.Net.Mail.
But the problem with them are:
System.Web.Mail: It works fine on ssl port 465 but is deprecated.
System.Net.Mail: Its the new API for email related applications. But it does not support ssl on port 465.
System.Web.Mail is based on CDOSYS. So i tried to search about CDOSYS and found that one can send emails directly using CDOSYS API without using either System.Web.Mail or System.Net.Mail. So thought sharing it with you..:hap2:
First you will need to add reference of "Microsoft CDO for windows 2000 library" from the COM components references.
Next the code for sending email is like below:
CDO.MessageClass Message = new CDO.MessageClass();
CDO.ConfigurationClass iConf = new CDO.ConfigurationClass();
iConf.Fields[CDO.CdoConfiguration.cdoSendUsingMethod].Value =
CDO.CdoSendUsing.cdoSendUsingPort;
iConf.Fields[CDO.CdoConfiguration.cdoSMTPServerPort].Value = 465;
iConf.Fields[CDO.CdoConfiguration.cdoSMTPServer].Value = "smtp.gmail.com";
iConf.Fields[CDO.CdoConfiguration.cdoSMTPAuthenticate].Value =
CDO.CdoProtocolsAuthentication.cdoBasic;
iConf.Fields[CDO.CdoConfiguration.cdoSendUserName].Value = "user";
iConf.Fields[CDO.CdoConfiguration.cdoSendPassword].Value = "password";
iConf.Fields.Update();
Message.Configuration = iConf;
Message.AutoGenerateTextBody = true;
Message.From = from;
Message.To = Recipients;
Message.CC = RecipientsCC;
Message.Subject = Subject;
Message.HTMLBody = htmlbody;
Message.Send();
Happy emailing......:hap2:
Recently I have been searching for an API which can send emails through SSL enabled servers like gmail.com in ASP.NET. For this purpose, ASP.NET is already having two API's : System.Web.Mail and System.Net.Mail.
But the problem with them are:
System.Web.Mail: It works fine on ssl port 465 but is deprecated.
System.Net.Mail: Its the new API for email related applications. But it does not support ssl on port 465.
System.Web.Mail is based on CDOSYS. So i tried to search about CDOSYS and found that one can send emails directly using CDOSYS API without using either System.Web.Mail or System.Net.Mail. So thought sharing it with you..:hap2:
First you will need to add reference of "Microsoft CDO for windows 2000 library" from the COM components references.
Next the code for sending email is like below:
CDO.MessageClass Message = new CDO.MessageClass();
CDO.ConfigurationClass iConf = new CDO.ConfigurationClass();
iConf.Fields[CDO.CdoConfiguration.cdoSendUsingMethod].Value =
CDO.CdoSendUsing.cdoSendUsingPort;
iConf.Fields[CDO.CdoConfiguration.cdoSMTPServerPort].Value = 465;
iConf.Fields[CDO.CdoConfiguration.cdoSMTPServer].Value = "smtp.gmail.com";
iConf.Fields[CDO.CdoConfiguration.cdoSMTPAuthenticate].Value =
CDO.CdoProtocolsAuthentication.cdoBasic;
iConf.Fields[CDO.CdoConfiguration.cdoSendUserName].Value = "user";
iConf.Fields[CDO.CdoConfiguration.cdoSendPassword].Value = "password";
iConf.Fields.Update();
Message.Configuration = iConf;
Message.AutoGenerateTextBody = true;
Message.From = from;
Message.To = Recipients;
Message.CC = RecipientsCC;
Message.Subject = Subject;
Message.HTMLBody = htmlbody;
Message.Send();
Happy emailing......:hap2: