Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2012, 04:48 PM
Authorized User
 
Join Date: Aug 2011
Posts: 44
Thanks: 14
Thanked 0 Times in 0 Posts
Default Page 532 - HTML file as the email's body

In the "How it works" of the "Try it out" of page 532 you say that we can use either a text file or an HTML file as the email's body.

The text file works well, as you show in the Try it out.
But if the BodyFileName property points to an HTML file like the following:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
Good morning <% UserName %>, 
<br /><br />
at <a>www.PlanetWrox.com</a>, a new account was created with the following details: 
<br /><br />
User:      <% UserName %>
<br />
Password:  <% Password %>

<br /><br /><br />
We look forward to your contribution
<br /><br />
The Planet Wrox team
<br /><br />
<img src="../Images/Banner480x60.gif" alt="Planet Wrox banner" />
</body>
</html>
the opening and closing tags will be sent in the email as plain text.

How can I avoid that ?

Thank you
 
Old April 29th, 2012, 05:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

When sending mail as HTML, there are a few things you need to take into account:

1. You need to set IsBodyHhtml to true on the MailMessage object:

Code:
myMessage.IsBodyHtml = true;
2. You don't need to send the doctype and HTML / body tags. All you need is the part within the <body> tags.

3. Images need to be resolvable at the client. In other words, this:

Code:
<img src="../Images/Banner480x60.gif" alt="Planet Wrox banner" />
will never work as the image will be searched for at the user's local machine. Instead, you need a full URL, like this:

Code:
<img src="http://www.yourdomain.com/Images/Banner480x60.gif" alt="Planet Wrox banner" />
If you're testing this locally, you can use http://localhost:12345 where 12345 is the port number of your development server.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 15.page 532.step 5 leemark2k3 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 September 13th, 2010 04:19 PM
Chapter 15, Page 532-533 Loophole3 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 September 13th, 2009 05:45 AM
Getting a Text file from a HTML File or web page rajesh.java Java Basics 1 January 20th, 2007 08:36 AM
HTML Email's Unicode Truncated When Using CDONTS lohcc Classic ASP Basics 0 July 25th, 2004 10:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.