How to send plain text emails that are HTML formatted?

A nice feature of modern email programs is that you can send and receive email that is formatted using HTML commands, containing text and images- and sometimes even JavaScript code for animations and the like. If you want to create such messages on your Web server, this is no problem because CDONTS supports the creation of HTML messages. A sample email with an attached image is presented here.


Sending an email with an html body

<% @language = VBScript %>
<%
option explicit
dim objMail, htmlBodyText
set objMail = server.createobject (“CDONTS. Newmail”)
htmlBodyText = “<! DOCTYPE HTML PUBLIC “ “ -//W3C//DTD HTML 4.0 TRANSITIONAL// EN” “ > “
htmlBodyText = htmlBodyText & <html>
htmlBodyText = htmlBodyText & <head>
htmlBodyText = htmlBodyText & “<title>A New Website is Launched</title>
htmlBodyText = htmlBodyText & “</head>
htmlBodyText = htmlBodyText & “<body bgcolor = #GAEFA>”
htmlBodyText = htmlBodyText & “<right>
htmlBodyText = htmlBodyText & “<p> A brand new website that teaches ''
htmlBodyText = htmlBodyText & “ASP Quickly“ “ and easily < a href = “ “ http://www.newdomainurlhere” ”>”
htmlBodyText = htmlBodyText & “http: // www. http://www.newdomainurlhere</a>.</p>”
htmlBodyText = htmlBodyText & “<img src=” “someimage. Gif “> “
htmlBodyText = htmlBodyText & “</center>”
htmlBodyText = htmlBodyText & “ <”/body>
htmlBodyText = htmlBodyText & “ </html>
objMail. From =”webmaster@newdomainurlhere”
objMail. To= “ someone@someoneurlhere”
objMail. Subject = “ Learn ASP Quickly”
objMail. Bodyformat = 0
objMail. Mailformat = 0
objMail.body = htmltext
objMail. AttachUrl server. Mapath (“ someimage.gif”), “someimage.gif”
objMail. Send
set objmail = nothing
%>

The major part of this listing deals with creating the appropriate HTML text. It is standard HTML, and line 17 even includes an image. When you add images to your HTML message, you must change the mail and body format of your email message. The necessary changes are made in the lines 25 and 26”

objMail.Bodyformat = 0
objMail.Mailformat = 0

The body format determines whether the message is plin text (1) or can contain HTML (0). Next you must determine the mail format, which describes how the mail is composted: it can be either a text message (1) or a MIME formatted (0) message. When you attach files, you should use the MIME type, which leads to the final new statement in this example:

objMail.AttachUrl server.Mapath (“softwing.gif”), “softwing.gif”

when using an image in the HTML message, you must specify its physical path as well as URL path that can be used in the message (<IMG> tag) to refer to it. By sending the email on line 31 using the well-known send method, it is on the way to the destination address.


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.