Overview
This article will demonstrate how to format Email Messages using Email Factory for .NET.
Code Example
Download licenseEmail.txt
| Download EM.vb | Download EM.cs
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Jscape.Email;
5:
6: namespace EmailMessage_NET
7: {
8: class EM
9: {
10: EmailMessage message = null;
11: public EM(string to, string from)
12: {
13: message = new EmailMessage(to, from);
14: }
15:
16: public void setBody(string body)
17: {
18: this.message.SetBody(body);
19: }
20:
21: public void setSubject(string subject)
22: {
23: this.message.Subject = subject;
24: }
25:
26: public void setPriority(int priority)
27: {
28: this.message.Priority = priority;
29: }
30:
31: public string getBody()
32: {
33: return this.message.GetBody();
34: }
35:
36: public void addHeader(string name, string value)
37: {
38: this.message.AddHeader(new MimeHeader(name, value));
39: }
40:
41: public void addAttachment(string file)
42: {
43: this.message.AddAttachment(new Attachment(file));
44: }
45:
46: public void setContentType(string contentType)
47: {
48: this.setContentType(contentType);
49: }
50:
51: static void Main(string[] args)
52: {
53: try
54: {
55: string to = "to@to.com";
56: string from = "from@from.com";
57: EM e = new EM(to, from);
58: e.addHeader("X-Mailer", "Microsoft Outlook");
59: e.setContentType("text/html");
60: }
61: catch (Exception e)
62: {
63: Console.WriteLine(e.Message);
64: }
65:
66: Console.WriteLine("Press any key to exit ... ");
67: Console.Read();
68: }
69: }
70: }
Lines 1-4 : Necessary import statements.
Lines 10-14 : Initialize EmailMessage instance.
Lines 16-19 : Set email message body.
Lines 21-24 : Set email message subject.
Lines 26-29 : Set email priority.
Lines 31-34 : Get email message body.
Lines 36-39 : Add header to email message.
Lines 41-44 : Add attachment to email message.
Lines 46-49 : Set content type.
Lines 57 : Initialize EM instance.
Comments