Mailjet and Asp Code Sample

Install

Une fonction SendMail avec authentification en VBScript ASP vieille version sans .NET.

 
 <!--
    METADATA
    TYPE="typelib"
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
    NAME="CDO for Windows 2000 Library"
-->
<%
Function SendMail(SMTPServer, SMTPUserName, SMTPPassword, EMailFrom, EMailTo, EMailCc, EMailBcc, EMailSubject, EMailType, EMailContent)
    Dim cdoConfig
    Dim cdoMessage
    Dim intErr
 
    Set cdoConfig = CreateObject("CDO.Configuration")
    With cdoConfig.Fields
         .Item(cdoSendUsingMethod) = cdoSendUsingPort
         .Item(cdoSMTPServer) = SMTPServer
         .Item(cdoSMTPAuthenticate) = 1
         .Item(cdoSendUsername) = SMTPUserName
         .Item(cdoSendPassword) = SMTPPassword
         .Update
    End With
 
    Set cdoMessage = CreateObject("CDO.Message")
    With cdoMessage
         Set .Configuration = cdoConfig
         If Len(Trim(CStr(EMailFrom))) = 0 Then
              .From = SMTPUserName
         Else
              .From = EMailFrom
         End If
         .To = EMailTo
         If Len(Trim(CStr(EMailCc))) <> 0 Then .Cc = EMailCc
         If Len(Trim(CStr(EMailBcc))) <> 0 Then .Bcc = EMailBcc
         .Subject = EmailSubject
         If EMailType = "text" Then
              .TextBody = EMailContent
         ElseIf EMailType = "html" Then
              .HTMLBody = EMailContent
         End If
         .Send
 
         intErr = Err.Number
   End With
 
   Set cdoMessage = Nothing
   Set cdoConfig = Nothing
 
   SendMail = intErr
End Function
%>
 
 
<%@Language=VBScript%>
<% Option Explicit %>
<!-- #include virtual = "/Includes/Email.asp" -->
'Autres includes...
-----------------
-----------------
-----------------
'Votre code ASP habituel ensuite...
<%
-----------------
-----------------
-----------------
%>
 

Usage

Here is an example on how to send an e-mail:

 
<%
'Declare Variables
Dim intError
Dim strResult
 
intError = SendMail("in.mailjet.com", "CleAPI", "MotdepasseAPI", "expediteur@example.com", "destinataire@example.com", "", "", "Sujet de ce message", "text", "Bienvenue dans le contenu du message !")
If intError = 0 Then
    'No errors, mail sent
    strResult = "Le message a bien ete envoye"
Else
    strResult = "Une erreur s'est produite pendant l'envoi du message"
    'Code de traitement d'erreur
    -----------------
    -----------------
    -----------------
End If
 
'Informer du resultat
Response.Write(strResult)
%>