Overview
This article will demonstrate how to create html based email messages using Email Factory for .NET.
Code Example
Download licenseEmail.txt
| Download HTMLMessage.cs
| Download HTMLMessage.vb
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Jscape.Email;
5:
6: namespace HTMLEmailMessage
7: {
8: class HTMLMessage
9: {
10: HtmlEmailMessage message = null;
11: public HTMLMessage(string to, string from)
12: {
13: message = new HtmlEmailMessage();
14: message.To = to;
15: message.From = from;
16: }
17:
18: public void setTextBody(string body)
19: {
20: message.SetTextBody(body);
21: }
22:
23: public void setHtmlBody(string body)
24: {
25: message.SetHtmlBody(body);
26: }
27:
28: public void embedImage(string file, string str)
29: {
30: message.Embed(new System.IO.FileInfo(file), str);
31: }
32:
33: static void Main(string[] args)
34: {
35: try
36: {
37: string to = "to@to.com";
38: string from = "from@from.com";
39: HTMLMessage m = new HTMLMessage(to, from);
40: m.setTextBody("text body");
41: m.setHtmlBody("<html><body>this is the body.</body></html>");
42: m.embedImage("image", "12345");
43: }
44: catch (Exception e)
45: {
46: Console.WriteLine(e.Message);
47: }
48:
49: Console.WriteLine("Press any key to exit ... ");
50: Console.Read();
51: }
52: }
53: }
Lines 1-4 : Necessary import statements.
Lines 10-16 : Initialize HtmlEmailMessage instance.
Lines 18-21 : Set email message body.
Lines 28-31 : Embed image in the message.
Line 39 : Initialize HtmlMessage instance.
Comments