using System.Net; using System.Net.Mail; using System.Text; using api.Interfaces; using models.Core; using models.Response; namespace api.Services; public class EmailService(IConfiguration config) : IEmailService { public void SendEmail(Ticket ticket, EventDetails @event) { using var client = new SmtpClient(config.GetSection("Email:Server").Value); client.UseDefaultCredentials = false; var auth = new NetworkCredential(config.GetSection("Email:UserName").Value, config.GetSection("Email:Password").Value); client.Credentials = auth; var from = new MailAddress(config.GetSection("Email:From").Value); var to = new MailAddress(ticket.Patron.Email); var emailMessage = new MailMessage(from, to); emailMessage.ReplyToList.Add(from); emailMessage.Subject = $"Tickets - {@event.Name}"; emailMessage.SubjectEncoding = Encoding.UTF8; emailMessage.IsBodyHtml = true; emailMessage.Body = GenerateTicketBody(ticket, @event); client.Send(emailMessage); } private string GenerateTicketBody(Ticket ticket, EventDetails @event) { var sb = new StringBuilder(); const string cardStyle = "margin: 15px; padding: 5px; backdrop-filter: blur(25px) saturate(112%); -webkit-backdrop-filter: blur(25px) saturate(112%); background-color: rgba(255, 255, 255, 0.11); border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.125); width: fit-content;"; const string columnStyle = "display: flex; flex-direction: column; justify-content: center;"; const string rowStyle = "display: flex; flex-direction: row; justify-content: center; align-items: baseline;"; const string qrCodeStyle = "height: 150px; width: 150px; padding: 10px;"; const string imagePath = "Assets/pso-logo.png"; sb.AppendLine($"
"); sb.AppendLine($"
"); sb.AppendLine($"\"Parma"); sb.AppendLine("
"); //closes #talentLogo sb.AppendLine($"
"); sb.AppendLine($"\"QR"); sb.AppendLine("
"); //closes #qrCode sb.AppendLine($"
"); sb.AppendLine($"
"); sb.AppendLine($"{@event.Talent.Name}"); sb.AppendLine($"{@event.Name}"); sb.AppendLine($"{@event.Description}"); sb.AppendLine($"{@event.Date.ToString("F")}"); sb.AppendLine($"{@event.Venue.Name}"); sb.AppendLine($"{@event.Venue.Description}"); sb.AppendLine($"{@event.Venue.AddressOne}"); sb.AppendLine($"{@event.Venue.City} {@event.Venue.State} {@event.Venue.Zip}"); sb.AppendLine("
"); //closes #venue nested card sb.AppendLine("
"); //closes #venue sb.AppendLine("
"); //closes #ticket return sb.ToString(); } }