Exemplo n.º 1
0
        /// <summary>
        /// Sends the <paramref name="message"/> and returns a <see cref="MessageSendResult"/>.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <returns>The result of the send operation.</returns>
        public MessageSendResult Send(MailMessageSerializable message)
        {
            if (this.Client == null)
            {
                throw new InvalidOperationException(ExceptionMessages.ClientNotSet);
            }

            MailMessage mailMessage = new MailMessage();
            new MessageConverter().Convert(message, mailMessage);

            try
            {
                this.Client.Send(mailMessage);
                return new MessageSendResult
                       {
                        Ok = true
                    };
            }
            catch (SmtpException e)
            {
                return new MessageSendResult
                       {
                    Ok = false,
                    Description = e.Message
                };
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populates <paramref name="target"/> with properties copied from <paramref name="source"/>.
        /// </summary>
        /// <param name="source">The source object to copy.</param>
        /// <param name="target">The target object to populate.</param>
        internal void Convert(MailMessageSerializable source, MailMessage target)
        {
            this.Convert(source.To, target.To);
            this.Convert(source.Cc, target.CC);
            this.Convert(source.Bcc, target.Bcc);

            target.From = this.Convert(source.Sender);
            target.Sender = target.From;
            target.Subject = source.Subject;
            target.Body = source.Body;
            target.IsBodyHtml = source.IsBodyHtml;

            this.Convert(source.Attachments, target.Attachments);

            target.Priority = (MailPriority)Enum.Parse(typeof(MailPriority), source.Priority.ToString("G"));
        }