Milan
Milan

Reputation: 1019

Best way to create complex html email message with asp.net, how?

After user places an order I have to send detailed email message containing order details, instructions for payment, some additional text etc.

I want to create nicely formatted HTML email message.

By now I found two options:

This second option is more visual and easier to implement except:

How to load page and render it? Do you have any other ideas or suggestions for this task?

Upvotes: 2

Views: 1153

Answers (5)

awake
awake

Reputation:

I'll use a template like Jay mentioned.

Below resource might turn out useful for you.

http://dotnettricks.com/blogs/roberhinojosablog/archive/2006/05/12/57.aspx

Upvotes: 0

Mark Brittingham
Mark Brittingham

Reputation: 28865

In a similar situation I store a template email message in my database so that the people who use our software can modify the message. It is created (by the user) using the online HTML editor control from Telerik. Within this message, I support several "mailmerge" type fields that all have the pattern {FirstName}, {LastName}, etc.

When it is time to send the message, I pull the formatted text from the database, use string replace to fill in any slots in the template, and then send it. I guess the key is that I know the message is HTML formatted because the Telerik control helps ensure that it is so. However, there is no reason why you couldn't create your HTML and then just save it for later use.

The .aspx page route? I just wouldn't do it. It is way overkill and doesn't offer you any advantages.

Upvotes: 1

Mike Robinson
Mike Robinson

Reputation: 25159

Try using a template stored in a .NET string resource file. Down the line this will make localization a lot easier too.

Upvotes: 0

Cerebrus
Cerebrus

Reputation: 25775

Well, IMO, your basic problem amounts to "How do I convert an ASPX resource into an HTML string to pass to the MailMessage Body property ?"

You could do that simply by using a WebRequest to the ASPX URL in question and read that response into a Stream. Then simply read the stream into a string and your primary problem is solved.

Edit: Here's an article that illustrates this concept.

Upvotes: 3

Jay S
Jay S

Reputation: 7994

Personally, I'd want to use a template, either in a database, or as a file that gets loaded. This template would have most of the content for the email in HTML, with tokens that I can replace with the content.

ex.

<b>Receipt for order # [[ordernum]]</b>

That way I could use simple string replacement to place the dymanic content into the email, without having to build the whole email every time it needs to be sent.

Upvotes: 2

Related Questions