private static Email Map(EMailHtmlForsendelseDTO request)
 {
     EmailUser sender = Map(request.Sender);
     Email mail = new Email(sender);
     mail.To.AddRange(Map(request.To));
     mail.Cc.AddRange(Map(request.Cc));
     mail.Bcc.AddRange(Map(request.Bcc));
     mail.Subject = request.Subject;
     mail.Body = Map(request.Body);
     mail.Attachments.AddRange(Map(request.Attachments));
     return mail;
 }
Пример #2
0
        internal bool TrySend(Email mail)
        {
            string step = "";
            Exception failedByException = null;
            string possibleFailReason = "";

            try
            {
                if (mail == null)
                {
                    throw new ArgumentNullException("Input parameter: mail");
                }

                step = "Building MailMessage";
                MailMessage localMail = mail.BuildMail(ref step);

                step = "Building SmtpGateway and sending mail";
                SendMail(localMail, ref step, ref possibleFailReason);
            }
            catch (Exception exception)
            {
                failedByException = exception;
            }

            if (failedByException != null)
            {
                string errorMessage = "## FAILED ##";
                if (!String.IsNullOrEmpty(step))
                {
                    errorMessage += Environment.NewLine + "Step: " + Environment.NewLine + step;
                }

                if (!String.IsNullOrEmpty(possibleFailReason))
                {
                    errorMessage += Environment.NewLine + "Possible Reason: " + Environment.NewLine + possibleFailReason;
                }
                mail.FailedByException = new Exception(errorMessage, failedByException);
            }

            return failedByException == null;
        }