Mail incluant une image avec methode cdo

JackHerrer Messages postés 1 Date d'inscription mardi 31 août 2004 Statut Membre Dernière intervention 20 janvier 2012 - 20 janv. 2012 à 10:37
Nicolas_kojack Messages postés 136 Date d'inscription vendredi 19 novembre 2004 Statut Membre Dernière intervention 25 mai 2012 - 25 mai 2012 à 14:07
bonjour

je souhaite envoyer un mail en vbs en incluant une image qu'accepterais outlook;
En effet, par defaut outlook bloque les images.

j'ai donc trouver une astuce grace à google :

Const CdoReferenceTypeName = 1
Dim objCDO, objBP
Set objCDO = Server.CreateObject("CDO.Message")
objCDO.MimeFormatted = True
objCDO.To = "you@yourdomain.com"
objCDO.From = "you@yourdomain.com"
objCDO.Subject = "Embedded image demo"
objCDO.HTMLBody = "<html>Check this out: </html>"

' Here's the good part, thanks to some little-known members.
' This is a BodyPart object, which represents a new part of the multipart MIME-formatted message.
' Note you can provide an image of ANY name as the source, and the second parameter essentially
' renames it to anything you want.  Great for giving sensible names to dynamically-generated images.
Set objBP = objCDO.AddRelatedBodyPart(Server.MapPath("/images/myimage.gif"), "myimage.gif", CdoReferenceTypeName)

' Now assign a MIME Content ID to the image body part.
' This is the key that was so hard to find, which makes it 
' work in mail readers like Yahoo webmail & others that don't
' recognise the default way Microsoft adds it's part id's,
' leading to "broken" images in those readers.  Note the
' < and > surrounding the arbitrary id string.  This is what
' lets you have SRC="cid:myimage.gif" in the IMG tag.
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage.gif>"
objBP.Fields.Update

objCDO.Send


Mais j'ai un message d'erreur sur l'objet server :

erreur : objet requis: 'server'
code 800A01A8

Merci d'avance pour vos aides.

2 réponses

Djoulzz Messages postés 1 Date d'inscription vendredi 23 mars 2012 Statut Membre Dernière intervention 23 mars 2012
23 mars 2012 à 14:46
Salut,

il te manque l'affectation des champs de configuration:

objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mon serveur smtp"

et éventuellement:
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
objCDO.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")
0
Nicolas_kojack Messages postés 136 Date d'inscription vendredi 19 novembre 2004 Statut Membre Dernière intervention 25 mai 2012
25 mai 2012 à 14:07
J'arrive avec beaucoup de retard mais le "server" est utilisable en asp pas en vbscript, en VBS tu mets directement CreateObject :

Set objCDO = CreateObject("CDO.Message")


Autre chose la méthode server.mappath n'existe pas en vbscript tu devras utiliser un objet Scripting.FileSystemObject et me semble t'il GetAbsolutePath pour récupérer ton chemin vers le fichier.

A priori sinon comme le dit Djoulzz ton code renvoi une erreur en asp 3.0 de sendusing donc il faut surement balancer de la configuration.
0
Rejoignez-nous