📨 EmailGenerationService Documentation


Table of Contents

  1. Overview & Purpose
  2. UML Class Diagram
  3. Dependencies & Technologies
  4. Interfaces & Implementations
  5. Key Functional Methods
  6. Data & View Models
  7. Helper Methods & Utilities
  8. Error Handling & Return Types
  9. Third‑party Integrations
  10. Usage Examples
  11. Sequence Diagram
  12. 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.Description by ": " into Issue & Detailed Description.
    • Renders a table of ticket metadata.
    • Adds link to track ticket.
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() from IrbyImaging.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.”

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.Status is typically an enum with a [Display(Name="…")] attribute; GetDisplayName() extracts its friendly name.


7. Helper Methods & Utilities 🔧

  • GetDisplayName()
    An extension in IrbyImaging.Utility that 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 ticket and employee are non-null. Caller must validate or catch ArgumentNullException.
  • 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. 🚀