/// <summary> /// Initializes an instance with the specified disposition notification type and action and sending modes /// </summary> /// <param name="notification">The disposition notification type</param> /// <param name="sendType">The sending mode type</param> /// <param name="triggerType">The action (trigger) mode type</param> /// <param name="isError">Notification for an error</param> public Disposition(MDNStandard.TriggerType triggerType, MDNStandard.SendType sendType, MDNStandard.NotificationType notification, bool isError) { this.TriggerType = triggerType; this.SendType = sendType; this.Notification = notification; this.IsError = isError; }
/// <summary> /// To simplify outbound mail sending, SMTP Server allows you to drop new messages into a pickup folder /// You don't need to use SmtpClient or some other SMTP client /// </summary> public void Send(IncomingMessage envelope, string pickupFolder, DirectAddressCollection senders, MDNStandard.NotificationType notificationType) { if (string.IsNullOrEmpty(pickupFolder)) { throw new ArgumentException("value null or empty", "pickupFolder"); } if (senders.IsNullOrEmpty()) { return; } foreach (NotificationMessage notification in this.Produce(envelope, senders.AsMailAddresses(), notificationType)) { string filePath = Path.Combine(pickupFolder, Extensions.CreateUniqueFileName()); notification.Save(filePath); } }
/// <summary> /// Parse RFC 3798, Disposition types, 3.2.6.2, includes type (processed) mentioned in document but /// (failed) added per Implementation Guide for Delivery Notification in Direct /// </summary> /// <param name="value">input text</param> /// <returns><see cref="MDNStandard.NotificationType"/> value</returns> public static MDNStandard.NotificationType ParseNotificationType(string value) { if (string.IsNullOrEmpty(value)) { throw new MDNException(MDNError.InvalidNotificationType); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Processed)) { return(MDNStandard.NotificationType.Processed); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Dispatched)) { return(MDNStandard.NotificationType.Dispatched); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Displayed)) { return(MDNStandard.NotificationType.Displayed); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Deleted)) { return(MDNStandard.NotificationType.Deleted); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Denied)) { return(MDNStandard.NotificationType.Denied); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Error)) { return(MDNStandard.NotificationType.Error); } if (MDNStandard.Equals(value, MDNStandard.Disposition_Failed)) { return(MDNStandard.NotificationType.Failed); } throw new MDNException(MDNError.InvalidNotificationType); }
/// <summary> /// Parse RFC 3798, Disposition modes, 3.2.6.1, sending-mode /// </summary> /// <param name="value">input text</param> /// <returns><see cref="MDNStandard.SendType"/> value</returns> public static MDNStandard.SendType ParseSendType(string value) { if (string.IsNullOrEmpty(value)) { throw new MDNException(MDNError.InvalidSendType); } if (MDNStandard.Equals(value, MDNStandard.Send_Automatic)) { return(MDNStandard.SendType.Automatic); } if (MDNStandard.Equals(value, MDNStandard.Send_Manual)) { return(MDNStandard.SendType.UserMediated); } throw new MDNException(MDNError.InvalidSendType); }
/// <summary> /// Parse RFC 3798, Disposition modes, 3.2.6.1, action-mode /// </summary> /// <param name="value">input text</param> /// <returns><see cref="MDNStandard.TriggerType"/> value</returns> public static MDNStandard.TriggerType ParseTriggerType(string value) { if (string.IsNullOrEmpty(value)) { throw new MDNException(MDNError.InvalidTriggerType); } if (MDNStandard.Equals(value, MDNStandard.Action_Automatic)) { return(MDNStandard.TriggerType.Automatic); } if (MDNStandard.Equals(value, MDNStandard.Action_Manual)) { return(MDNStandard.TriggerType.UserInitiated); } throw new MDNException(MDNError.InvalidTriggerType); }
/// <summary> /// Tries to parse the final recipient - IF it is a mail address /// Else returns null /// </summary> /// <param name="value">input text</param> /// <returns><see cref="System.Net.Mail.MailAddress"/> object</returns> public static MailAddress ParseFinalRecipient(string value) { if (string.IsNullOrEmpty(value)) { return(null); } string[] parts = SplitField(value, MDNError.InvalidFinalRecipient); if (!MDNStandard.Equals(parts[0], MDNStandard.RecipientType_Mail)) { return(null); } try { return(new MailAddress(parts[1])); } catch (Exception ex) { throw new MDNException(MDNError.InvalidFinalRecipient, ex); } }
private List<NotificationMessage> GetNotificationMessages(IncomingMessage incoming, MDNStandard.NotificationType notificationType) { return incoming.Message.CreateNotificationMessages( incoming.Recipients.AsMailAddresses(), sender => Notification.CreateAck ( new ReportingUserAgent ( sender.Host , m_agent.Settings.Notifications.ProductName ) , m_agent.Settings.Notifications.Text , notificationType) ).ToList(); }
/// <summary> /// Tests if this message IS an MDN /// </summary> /// <param name="message"></param> /// <returns></returns> public static bool IsMDN(this Message message) { return(MDNStandard.IsReport(message)); }
/// <summary> /// Provides the appropriate <c>Disposition</c> header value for the <paramref name="type"/> /// </summary> /// <param name="type">The type to translate</param> /// <returns>A string representation suitable for inclusion in the disposition type section of the <c>Disposition</c> header value</returns> public static string AsString(this MDNStandard.NotificationType type) { return(MDNStandard.ToString(type)); }
/// <summary> /// Provides the appropriate <c>Disposition</c> header value for the <paramref name="type"/> /// </summary> /// <param name="type">The mode to translate</param> /// <returns>A string representation suitable for inclusion in the sending mode section of the <c>Disposition</c> header value</returns> public static string AsString(this MDNStandard.SendType type) { return(MDNStandard.ToString(type)); }
/// <summary> /// Generate notification messages (if any) for this source message /// </summary> /// <param name="envelope"></param> /// <param name="senders">sending acks on behalf of these message recipients</param> /// <param name="notificationType">processed or dispatched</param> /// <returns>An enumeration of messages</returns> public IEnumerable<NotificationMessage> Produce(IncomingMessage envelope, IEnumerable<MailAddress> senders, MDNStandard.NotificationType notificationType) { if (envelope == null) { throw new ArgumentNullException("envelope"); } if (senders != null && m_settings.AutoResponse) { IEnumerable<NotificationMessage> notifications = envelope.CreateAcks(senders, m_settings.ProductName, m_settings.Text, m_settings.AlwaysAck, notificationType); if (notifications != null) { foreach (NotificationMessage notification in notifications) { yield return notification; } } } }
/// <summary> /// Initializes an instance with the specified disposition notification type and action and sending modes /// </summary> /// <param name="notification">The disposition notification type</param> /// <param name="sendType">The sending mode type</param> /// <param name="triggerType">The action (trigger) mode type</param> public Disposition(MDNStandard.TriggerType triggerType, MDNStandard.SendType sendType, MDNStandard.NotificationType notification) : this(triggerType, sendType, notification, false) { }
/// <summary> /// Initializes an instance with the specified disposition notification type and automatic modes /// </summary> /// <param name="notification">The disposition notification type</param> /// <param name="isError">Notification is for an error</param> public Disposition(MDNStandard.NotificationType notification, bool isError) : this(MDNStandard.TriggerType.Automatic, MDNStandard.SendType.Automatic, notification, isError) { }
/// <summary> /// Create ACK MDN notifications for this message - IF MDNs should be generated. /// Since the message could have multiple recipients, an independant MDN is generated FROM each recipient. /// If no MDNs should be generated, returns NULL. /// - If there are no trusted domain recipients for the message, meaning there is nothing to ACK /// - If the message is itself an MDN /// </summary> /// <param name="senders">Sending Acks on behalf of these recipients</param> /// <param name="reportingAgentName">The name of the MTA or MUA that is generating this ack</param> /// <param name="textMessage">Optional text message to accompany the Ack</param> /// <param name="alwaysAck">Generate acks even when none were requested</param> /// <param name="notificationType">processed, dispatched or failed</param> /// <returns>An enumeration of NotificationMessage</returns> public IEnumerable<NotificationMessage> CreateAcks(IEnumerable<MailAddress> senders, string reportingAgentName, string textMessage, bool alwaysAck, MDNStandard.NotificationType notificationType) { if (senders == null) { throw new ArgumentException("senders"); } if (string.IsNullOrEmpty(reportingAgentName)) { throw new ArgumentException("reportingAgentName"); } if (this.Message.IsMDN()) { return null; } if (!this.Message.HasNotificationRequest()) { if (!alwaysAck) { return null; } // // Although an MDN was not explicitly requested, we are going to send one (as per the Direct spec). // To allow the MDN code to remain MDN RFC compliant & work naturally, we inject an MDN requested header // on behalf of the sender // this.Message.RequestNotification(this.Sender); } return this.Message.CreateNotificationMessages(senders, sender => Notification.CreateAck(new ReportingUserAgent(sender.Host, reportingAgentName), textMessage, notificationType) ); }
/// <summary> /// Create ACK MDN notifications for this message - IF MDNs should be generated. /// Since the message could have multiple recipients, an independant MDN is generated FROM each recipient. /// If no MDNs should be generated, returns NULL. /// - If there are no trusted domain recipients for the message, meaning there is nothing to ACK /// - If the message is itself an MDN /// </summary> /// <param name="reportingAgentName">The name of the MTA or MUA that is generating this ack</param> /// <param name="textMessage">Optional text message to accompany the Ack</param> /// <param name="alwaysAck">Generate acks even when none were requested</param> /// <param name="notificationType">processed, dispatched or failed</param> /// <returns>An enumeration of NotificationMessage</returns> public IEnumerable<NotificationMessage> CreateAcks(string reportingAgentName, string textMessage, bool alwaysAck, MDNStandard.NotificationType notificationType) { if (!this.HasDomainRecipients) { return null; } return CreateAcks(this.DomainRecipients.AsMailAddresses(), reportingAgentName, textMessage, alwaysAck, notificationType); }
/// <summary> /// Create ACK MDN notifications for this message - IF MDNs should be generated. /// Since the message could have multiple recipients, an independant MDN is generated FROM each recipient. /// If no MDNs should be generated, returns NULL. /// - If there are no trusted domain recipients for the message, meaning there is nothing to ACK /// - If the message is itself an MDN /// </summary> /// <param name="reportingAgentName">The name of the MTA or MUA that is generating this ack</param> /// <param name="textMessage">Optional text message to accompany the Ack</param> /// <param name="notificationType">processed, dispatched or failed</param> /// <returns>An enumeration of NotificationMessage</returns> public IEnumerable<NotificationMessage> CreateAcks(string reportingAgentName, string textMessage, MDNStandard.NotificationType notificationType) { return CreateAcks(reportingAgentName, textMessage, true, notificationType); }