Sending e-mail in ASP with CDOSYS

pradeep's Avatar author of Sending e-mail in ASP with CDOSYS
This is an article on Sending e-mail in ASP with CDOSYS in ASP.

Introduction



CDOSYS is a built-in component in ASP. This component is used to send e-mails with ASP.

Sending e-mail with CDOSYS



CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications.
CDOSYS is a built-in component in ASP. We will show you how to use this component to send e-mail with ASP.

How about CDONTs?



Microsoft has discontinued the use of CDONTs on Windows 2000, Windows XP and Windows 2003. If you have used CDONTs in your ASP applications, you should update the code and use the new CDO technology.

Examples using CDOSYS
Sending a text e-mail:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.TextBody="This is a message."
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending a text e-mail with Bcc and CC fields:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.Bcc="someoneelse@somedomain.com"
 
  myMail.Cc="someoneelse2@somedomain.com"
 
  myMail.TextBody="This is a message."
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending an HTML e-mail:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.HTMLBody = "<h1>This is a message."
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending an HTML e-mail that sends a webpage from a website:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.CreateMHTMLBody "http://www.go4expert.com"
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending an HTML e-mail that sends a webpage from a file on your computer:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.CreateMHTMLBody "file://c:/mydocuments/go4expert.htm"
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending a text e-mail with an Attachment:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.TextBody="This is a message."
 
  myMail.AddAttachment "c:\mydocuments\go4expert.txt"
 
  myMail.Send
 
  set myMail=nothing
 
  %>
Sending a text e-mail using a remote server:

Code: ASP
<%
 
  Set myMail=CreateObject("CDO.Message")
 
  myMail.Subject="Sending email with CDO"
 
  myMail.From="mymail@mydomain.com"
 
  myMail.To="someone@somedomain.com"
 
  myMail.TextBody="This is a message."
 
  myMail.Configuration.Fields.Item _
 
  ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
 
  'Name or IP of remote SMTP server
 
  myMail.Configuration.Fields.Item _
 
  ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
 
  ="smtp.server.com"
 
  '
Server port
 
  myMail.Configuration.Fields.Item _
 
  ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
 
  =25
 
  myMail.Configuration.Fields.Update
 
  myMail.Send
 
  set myMail=nothing
 
  %>
faital's Avatar
faital
Guest
Hi, This post is very informative, however I would like some specific information. If someone can help me then please send me a private message. Best Regards,
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Why PM? You can just post it here or in the forums section. If its something very personal you cannot discuss here you can use the PM.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
What specific information do you require faital?? Let me know!
pushthelimits's Avatar, Join Date: Aug 2008
Newbie Member
Quote:
Originally Posted by pradeep
What specific information do you require faital?? Let me know!
could you please give an idea how to send a mail using cdosys
using the folllowing code?


<%

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"

myMail.From="mymail@mydomain.com"

myMail.To="someone@somedomain.com"

myMail.TextBody="This is a message."

myMail.Send

set myMail=nothing

%>
i have a page say 1.asp ,if i click a send button on 1.asp, it will go to 2.asp wer this code is written.

i couldnt find the correct solution frm books and net, i tried a lot, no error is coming but mail is not sent.



am using asp ,msaccess for this project.
i have taken a asp connection/space from spaceforhost webhosting company.
when i enquired they told cdosys is supported by them.

is there any need of special server settings to run the code?