/// <summary>
        /// Send an email.
        /// </summary>
        /// <param name="subject">The subject of the email.</param>
        /// <param name="body">The body of the email.</param>
        /// <param name="receipients">The receipients of the email.</param>
        /// <param name="sender">The sender of the email.</param>
        /// <param name="isBodyHtml">Whether the body is html or not.</param>
        /// <returns>Whether send performed successfully.</returns>
        public OperationResult SendEmail(string subject, string body, EmailReceipients receipients, MailAddress sender, bool isBodyHtml)
        {
            OperationResult <MailMessage> mailMessageOperation =
                Get.MailMessage(subject, body, receipients, sender, isBodyHtml);

            if (mailMessageOperation.HadErrors)
            {
                return(mailMessageOperation);
            }

            try {
                _smtpClient.Send(mailMessageOperation.Result);
            }
            catch (Exception ex) {
                return(new OperationResult(new[] { ex }));
            }

            return(new OperationResult());
        }
        public OperationResult SendEmail(string subject, string body, EmailReceipients receipients, MailAddress sender, bool isBodyHtml)
        {
            string email = Use.StringBuilder(builder => {
                EmailLoggingToBegin?.Invoke(this, new Utilities.EventArgs.GenericEventArgs <IFileNameSwappable>(_logger));
                builder.AppendLine("***** EMAIL *****\r\n");
                builder.AppendLine($"FROM : {sender.DisplayName}({sender.Address})\r\n");

                if (receipients.NoReceipientsSpecified)
                {
                    builder.AppendLine("** No Receipients Specified **");
                }
                else
                {
                    if (receipients.Receipients.Any())
                    {
                        builder.AppendLine($"TO : {string.Join("; ", receipients.Receipients.Select(rec => $"{rec.DisplayName}({rec.Address})")) };");
                    }
                    if (receipients.CCReceipients.Any())
                    {
                        builder.AppendLine($"CC : {string.Join("; ", receipients.CCReceipients.Select(rec => $"{rec.DisplayName}({rec.Address})")) };");
                    }
                    if (receipients.BlindCCReceipients.Any())
                    {
                        builder.AppendLine($"BCC : {string.Join("; ", receipients.BlindCCReceipients.Select(rec => $"{rec.DisplayName}({rec.Address})")) };");
                    }
                }

                builder.AppendLine($"\r\nSUBJECT : {subject}");

                builder.AppendLine($"Is Body HTML? {(isBodyHtml ? "Yes" : "No" )}");
                builder.AppendLine($"\r\nBODY :\r\n{body}");
                builder.AppendLine("\r\n***** EMAIL END *****");
            });
            OperationResult loggingOperation =
                _logger.Log(email);

            if (loggingOperation.WasSuccessful)
            {
                EmailLoggingCompletedSuccessfully?.Invoke(this, new Utilities.EventArgs.GenericEventArgs <string>(_logger.FileName));
            }
            return(loggingOperation);
        }
Beispiel #3
0
 public Task <OperationResult> SendEmailAsync(string subject, string body, EmailReceipients receipients, MailAddress sender, bool isBodyHtml) =>
 Task.FromResult(new OperationResult());