ASP Envoi d'e-mail avec CDOSYS


CDOSYS est un composant intégré dans ASP. Ce composant est utilisé pour envoyer des e-mails avec ASP.


Envoi de courrier électronique avec CDOSYS

CDO (Collaboration Data Objects) est une technologie Microsoft conçue pour simplifier la création d'applications de messagerie.

CDOSYS est un composant intégré dans ASP. Nous allons vous montrer comment utiliser ce composant pour envoyer des e-mails avec ASP.

Et les CDONT ?

Microsoft a arrêté l'utilisation des CDONT sur Windows 2000, Windows XP et Windows 2003. Si vous avez utilisé des CDONT dans vos applications ASP, vous devez mettre à jour le code et utiliser la nouvelle technologie CDO.

Exemples utilisant CDOSYS

Envoi d'un e-mail texte :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
myMail.TextBody = "This is a message."
myMail.Send
set myMail = nothing
%>

Envoi d'un e-mail texte avec les champs Cci et CC :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
myMail.Bcc = "[email protected]"
myMail.Cc = "[email protected]"
myMail.TextBody = "This is a message."
myMail.Send
set myMail = nothing
%>

Envoi d'un e-mail HTML :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
myMail.HTMLBody = "<h1>This is a message.</h1>"
myMail.Send
set myMail = nothing
%>

Envoi d'un e-mail HTML qui envoie une page Web à partir d'un site Web :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To ="[email protected]"
myMail.CreateMHTMLBody "https://www.w3schools.com/asp/"
myMail.Send
set myMail = nothing
%>


Envoi d'un e-mail HTML qui envoie une page Web à partir d'un fichier sur votre ordinateur :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
myMail.CreateMHTMLBody "file://c:/mydocuments/test.htm"
myMail.Send
set myMail = nothing
%>

Envoi d'un e-mail texte avec une pièce jointe :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
myMail.TextBody = "This is a message."
myMail.AddAttachment "c:\mydocuments\test.txt"
myMail.Send
set myMail = nothing
%>

Envoi d'un e-mail texte à l'aide d'un serveur distant :

<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = "[email protected]"
myMail.To = "[email protected]"
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
%>