Tuesday, December 15, 2009

Sending emails using Microsoft CDOSYS.

After looking around for a while i realized that CDONT's has been deprecated.I am not sure if Microsoft still ships their server OS with CDONT's. These libraries are still available as en external resource that can be accessed either by adding meta tags to your asp application or by creating a CDO configuration object.
Here is a sample code on how you can send emails using Microsoft CDOSYS using a remote server.




<%
dim htmlMess
htmlMess=""
htmlMess=htmlMess & " "
htmlMess=htmlMess & " Sending email using Microsoft CDOSYS"
htmlMess=htmlMess & " "
htmlMess=htmlMess & " "
htmlMess=htmlMess & " &Request("email")"
htmlMess=htmlMess & " "
htmlMess=htmlMess & " "

Set emailMess=CreateObject("CDO.Message")
emailMess.Subject="This is a test email sent using CDOSYS"
emailMess.From="fromemail@yourdomain.com"
emailMess.To="toemail@somedomain.com"
emailMess.Cc="cc@somedomain.com"
emailMess.Bcc="bcc@somedomain.com"
emailMess.AddAttachment "D:\att.rar"
emailMess.HTMLBody=htmlMess
emailMess.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
emailMess.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.yourdomain.com"
'Server port
emailMess.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
emailMess.Configuration.Fields.Update
emailMess.Send
set emailMess=nothing

%>



Another fact that i would like to mention is that,you necessarily don't have to write code for sending email as your hosting provider is supposed to take care of sending emails.Do talk to your hosting provider about email component as they are supposed to provide you with this facility.





No comments: