đ¨ EmailGenerationService Documentation
Table of Contents
- Overview & Purpose
- UML Class Diagram
- Dependencies & Technologies
- Interfaces & Implementations
- Key Functional Methods
- Data & View Models
- Helper Methods & Utilities
- Error Handling & Return Types
- Thirdâparty Integrations
- Usage Examples
- Sequence Diagram
- Conclusion
1. Overview & Purpose
EmailGenerationService is a core service in the IrbyImaging system designed to standardize and centralize the creation of HTMLâformatted email messages for various ticketing actions (incidents, requests, updates, closures, cancellations, approvals) and passwordâreset confirmations. By encapsulating subject line conventions and message templates, it ensures consistent, maintainable, and localizable communications. đŹ
2. UML Class Diagram
classDiagram
IEmailGenerationService <|.. EmailGenerationService
class IEmailGenerationService {
<<interface>>
+ForIncident(Ticket) (string email, string subj, string msg)
+ForRequest(Ticket) (string, string, string)
+ForUpdate(Ticket, Update) (string, string, string)
+ForClosingATicket(Ticket) (string, string, string)
+ForCancellingATicket(Ticket) (string, string, string)
+ForApproval(Ticket, string, string) (string, string, string)
+ForPasswordReset(Employee) (string, string, string)
}
class EmailGenerationService {
+ForIncident(...)
+ForRequest(...)
+ForUpdate(...)
+ForClosingATicket(...)
+ForCancellingATicket(...)
+ForApproval(...)
+ForPasswordReset(...)
}
class Ticket {
+Id: Guid
+TicketNumber: int
+CustomerName: string
+CallBackNumber: string
+ResponseEmail: string
+CreatedBy: string
+CreatedOn: DateTime
+Description: string
+Status: StatusEnum
}
class Update {
+UpdatedBy: string
+Timestamp: DateTime
+Description: string
}
class Employee {
+FirstName: string
+WorkEmail: string
}
Ticket "1" --> "*" Update
Ticket --> EmailGenerationService : uses
Update --> EmailGenerationService : uses
Employee --> EmailGenerationService : uses
3. Dependencies & Technologies đ ď¸
| Category | Details |
|---|---|
| Language | C# (.NET Framework / .NET Core) |
| Assemblies | IrbyImaging.DomainClasses, IrbyImaging.Utility |
| Build System | MSBuild |
| HTML Emailing | Inline HTML tables, <style> tags for password reset styling |
| Encoding | System.Uri.EscapeDataString for mailto link parameters |
| External Links | Hardâcoded URLs to http://www.irbysystems.com/Tickets/Details/{ticket.Id} |
4. Interfaces & Implementations
IEmailGenerationService
public interface IEmailGenerationService
{
(string emailAddress, string subject, string message) ForIncident(Ticket ticket);
(string, string, string) ForRequest(Ticket ticket);
(string, string, string) ForUpdate(Ticket ticket, Update update);
(string, string, string) ForClosingATicket(Ticket ticket);
(string, string, string) ForCancellingATicket(Ticket ticket);
(string, string, string) ForApproval(Ticket ticket, string item, string createdByUsername);
(string, string, string) ForPasswordReset(Employee employee);
}
- Purpose: Defines the contract for generating email content for various ticket lifecycle events and password resets.
- Return Type: A ValueTuple of
(emailAddress, subject, message).
EmailGenerationService
public class EmailGenerationService : IEmailGenerationService
{
// Implementations of all methods...
}
- Implements:
IEmailGenerationService - Responsibilities: Builds subjects and HTML bodies for each scenario, using ticket or employee data.
5. Key Functional Methods đ§Š
5.1 ForIncident
- When: New incident ticket is created.
- Returns: Recipient, subject, HTML message.
- Highlights:
- Splits
ticket.Descriptionby": "into Issue & Detailed Description. - Renders a table of ticket metadata.
- Adds link to track ticket.
- Splits
var (to, subj, msg) = service.ForIncident(ticket);
5.2 ForRequest
- When: A service request (nonâincident) is submitted.
- Difference: Renders "Request Details" header and uses full description.
5.3 ForUpdate
- When: A technician or user adds an update to an existing ticket.
- Additional Data:
Update.UpdatedBy,Update.Timestamp,Update.Description. - Uses:
ticket.Status.GetDisplayName()fromIrbyImaging.Utility.
5.4 ForClosingATicket
- When: Ticket is marked as Closed.
- Subject: Indicates closure date and original creation info.
- Footer: Archive link.
5.5 ForCancellingATicket
- When: Ticket is Cancelled by user or admin.
- Similar to: Closing, with "cancelled" wording.
5.6 ForApproval
- When: An approval is needed for a specific item (e.g., access or purchase).
- Features:
- Generates Approve and Deny mailto links.
- Encodes subjects & default body via
Uri.EscapeDataString. - Renders buttons for quick approval flows.
5.7 ForPasswordReset
- When: An employee successfully resets their password.
- HTML Styling:
- Embedded
<style>block for header, content, footer classes. - Personalized greeting.
- Footer disclaimer: âThis is an automated message. Please do not reply.â
- Embedded
6. Data & View Models
| Model | Key Properties | Used In |
|---|---|---|
| Ticket | Id, TicketNumber, CustomerName, CallBackNumber,ResponseEmail, CreatedBy, CreatedOn, Description, Status | All ticketâbased methods |
| Update | UpdatedBy, Timestamp, Description | ForUpdate |
| Employee | FirstName, WorkEmail | ForPasswordReset |
Note:
ticket.Statusis typically an enum with a[Display(Name="âŚ")]attribute;GetDisplayName()extracts its friendly name.
7. Helper Methods & Utilities đ§
-
GetDisplayName()
An extension inIrbyImaging.Utilitythat reads[Display(Name="âŚ")]on an enum. -
Uri.EscapeDataString()
Encodes special characters in mailto query strings.
8. Error Handling & Return Types â ď¸
- Return Tuple: Always returns
(string emailAddress, string subject, string message). - Null Checks: Assumes
ticketandemployeeare non-null. Caller must validate or catchArgumentNullException. - Encoding: Ensures mailto links wonât break due to spaces or line breaks.
9. Thirdâparty Integrations
- MailTo Links: Uses mailto URIs to launch the userâs default email client for approvals.
- Hardâcoded URLs: Ticket tracking links point to
irbysystems.com. Consider configurable base URL for different environments (dev, staging, prod).
10. Usage Examples đĄ
// 1. Instantiate the service
IEmailGenerationService emailService = new EmailGenerationService();
// 2. Prepare a sample Ticket
var ticket = new Ticket {
Id = Guid.NewGuid(),
TicketNumber = 12345,
CustomerName = "ACME Corp.",
CallBackNumber = "555-1234",
ResponseEmail = "[email protected]",
CreatedBy = "jdoe",
CreatedOn = DateTime.UtcNow,
Description = "Network: Internet is down",
Status = StatusEnum.New
};
// 3. Generate email for a new incident
var (to, subject, body) = emailService.ForIncident(ticket);
// 4. Send via your SMTP/SendGrid/ServiceBus...
emailSender.Send(to, subject, body);
11. Sequence Diagram
sequenceDiagram
participant C as Customer
participant S as EmailGenerationService
participant M as MailSender (SMTP)
C->>S: Submit Ticket (Ticket object)
S->>S: Build Subject & HTML Body
S->>M: Send(emailAddress, subject, message)
M-->>C: Delivery Confirmation
12. Conclusion â
The EmailGenerationService centralizes all HTML email templates related to the ticket lifecycle and password resets, ensuring:
- Consistency in subject lines & formatting
- Maintainability with a single location for updates
- Extensibility for new ticket events or localization
By integrating with your mailâsending infrastructure, it streamlines communication and elevates the user experience across all helpâdesk interactions. đ