Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/articles/asp-tutorials/)
-   -   Sending e-mail in ASP with CDOSYS (http://www.go4expert.com/articles/sending-e-mail-asp-cdosys-t1565/)

pradeep 7Oct2006 14:33

Sending e-mail in ASP with CDOSYS
 

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 13Oct2006 11:34

Re: Sending e-mail in ASP with CDOSYS
 
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 13Oct2006 12:04

Re: Sending e-mail in ASP with CDOSYS
 
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 13Oct2006 12:24

Re: Sending e-mail in ASP with CDOSYS
 
What specific information do you require faital?? Let me know!

pushthelimits 8Aug2008 14:05

Re: Sending e-mail in ASP with CDOSYS
 
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?


All times are GMT +5.5. The time now is 07:27.