private async Task <bool> SendPaymentRequest(string sender, SendPaymentRequest paymentRequest, string requestUrl) { var body = new StringBuilder(); body.AppendLine("Hello!"); body.AppendLine($"{sender} requests you to pay {paymentRequest.Currency} {paymentRequest.Amount}."); if (!string.IsNullOrEmpty(paymentRequest.Description)) { body.AppendLine(); body.AppendLine("Description:"); body.AppendLine(paymentRequest.Description); } body.AppendLine(); body.AppendLine($"Pay here: {requestUrl}"); var email = new MailBuilder(this.mailConfig) .WithBody(body.ToString()) .WithSubject($"New payment request from {sender}") .AddRecipients(sender) .AddBccRecipients(paymentRequest.Recipients); if (paymentRequest.WithStatement) { using var file = new MemoryStream(); using (var fileWriter = new StreamWriter(file)) using (var csvHelper = new CsvWriter(fileWriter, CultureInfo.InvariantCulture)) { csvHelper.WriteHeader(typeof(Data.Transaction)); csvHelper.Flush(); fileWriter.WriteLine(); csvHelper.WriteRecords(paymentRequest.Transactions.OrderByDescending(t => t.CreatedOn)); } var fileBytes = file.ToArray(); email.WithAttachment("payments.csv", "text/csv", Convert.ToBase64String(fileBytes)); } return(await this.emailService.SendMail(email.Build())); }