private object FormatMessageEndPoint(MessageEndPoint endPoint) { var obj = new Dictionary <string, object>(); if (endPoint.Name != null) { obj["name"] = endPoint.Name; } obj["email"] = endPoint.Address; return(obj); }
/// <summary> /// Initializes an instance of the Message structure. /// </summary> /// <param name="from">The message sender.</param> /// <param name="to">An array of message main recipients.</param> /// <param name="cc">An array of message carbon copy recipients.</param> /// <param name="bcc">An array of message blind carbon copy recipients.</param> /// <param name="subject">The message subject.</param> /// <param name="bodies">The message bodies.</param> public Message(MessageEndPoint from, MessageEndPoint[] to, MessageEndPoint[] cc, MessageEndPoint[] bcc, string subject, MessageBody[] bodies) { if (from.IsValid == false) { throw new ArgumentException("Invalid 'from' information."); } if (to == null || to.Length == 0) { throw new ArgumentException("Missing 'to' information."); } else if (to.Any(x => x.IsValid == false)) { throw new ArgumentException("In 'to' argument, at least one instance is invalid."); } if (bodies != null && bodies.Any(x => x.IsValid == false)) { throw new ArgumentException("In 'bodies' argument, at least one instance is invalid."); } if (cc != null && cc.Length == 0) { cc = null; } if (bcc != null && bcc.Length == 0) { bcc = null; } if (string.IsNullOrWhiteSpace(subject)) { subject = null; } if (bodies != null && bodies.Length == 0) { bodies = null; } From = from; To = to; Cc = cc; Bcc = bcc; Subject = subject; Bodies = bodies; }
/// <summary> /// Sets the sender information of the message. /// </summary> /// <param name="endPoint">Sender information of the message.</param> /// <returns>Returns the current MessageBuilder for composition.</returns> public MessageBuilder SetFrom(MessageEndPoint endPoint) { from = endPoint; return(this); }