CREATE TABLE [dbo].[ATMail] (
    [Id]            INT             IDENTITY(1,1) NOT NULL,
    [Description]   NVARCHAR (256)  NULL,
    [EventID]       INT             NOT NULL,
    [ProcessID]     INT             NOT NULL,
    [ConnectionId]  INT             NULL,
    [Recipient]     NVARCHAR (512)  NOT NULL,
    [CC]            NVARCHAR (256)  NULL,
    [BCC]           NVARCHAR (256)  NULL,
    [From]          NVARCHAR (256)  NULL,
    [Reply]         NVARCHAR (256)  NULL,
    [Subject]       NVARCHAR (256)  NULL,
    [Message]       NVARCHAR (MAX)  NULL,
    [Enable]        BIT             NOT NULL DEFAULT 1,
    [Priority]      TINYINT         NOT NULL DEFAULT 0, -- 0: Low, 1: Normal, 2: High
    CONSTRAINT [PK_ATMail] PRIMARY KEY CLUSTERED ([Id]),
    CONSTRAINT [FK_Process] FOREIGN KEY ([ProcessID]) REFERENCES [dbo].[ATProcessDefinition] ([ProcessID]),
    CONSTRAINT [FK_Event] FOREIGN KEY ([EventID]) REFERENCES [dbo].[ATEventDefinition] ([EventId]),
    CONSTRAINT [FK_ATMail_ATConnection] FOREIGN KEY ([ConnectionId]) REFERENCES [dbo].[ATConnection] ([Id]),
    CONSTRAINT [CK_ATMail_Priority] CHECK ([Priority] BETWEEN 0 AND 2)
);
