AspGerman Wiki

Heutzutage ist eine Email ohne Grafiken, eine Vielzahl von Schriften oder -größen "megaout". Also auch dann, wenn man sie von einem Webformular generiert.

Der SMTP Service von IIS bietet mit den Collaboration Data Objects (CDONTS) eine Möglichkeit, HTML Mails ohne Probleme zu erzeugen. Der unten angeführte Democode erstellt über das CDONTS.NewMail Objekt eine HTML Mail, die ein Bild eingebettet hat. Dieses muß mit AttachUrl an die Email angehängt werden. Ansonst werden nur einfache Eigenschaften und Methoden des Objekts verwendet.

<% @LANGUAGE = VBScript %>
<%
Option Explicit
Dim objMail, htmlText
Set objMail = Server.CreateObject("CDONTS.NewMail")

htmlText = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
htmlText = htmlText & "<html>"
htmlText = htmlText & "<head>"
htmlText = htmlText & "<title>Meine erste HTML Email</title>"
htmlText = htmlText & "</head>"
htmlText = htmlText & "<body bgcolor=#ffffff>"
htmlText = htmlText & "<center>"
htmlText = htmlText & "<h1>HTML Email!</h1><p>"
htmlText = htmlText & "Mit besten Gr&uuml;&szlig;en von "
htmlText = htmlText & "<a href=""http://www.aspgerman.com"">"
htmlText = htmlText & "http://www.aspgerman.com</a>.</p>"
htmlText = htmlText & "<img src=""softwing.gif"">"
htmlText = htmlText & "</center>"
htmlText = htmlText & "</body>"
htmlText = htmlText & "</html>"

objMail.From = "webmaster@alphasierrapapa.com"
objMail.To = "christophw@alphasierrapapa.com"
objMail.Subject = "HTML in der Mail - kein Problem"
objMail.BodyFormat = 0
objMail.MailFormat = 0

objMail.Body = htmlText
objMail.AttachUrl Server.MapPath("softwing.gif"), "softwing.gif"

objMail.Send
%>

ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.