public void SendEmail(EmailDto model, FileSendEmail file = null) { var email = new MimeMessage(); email.Sender = MailboxAddress.Parse(_mailSettings.Mail); email.To.Add(new MailboxAddress(model.ToName, model.ToAddress)); email.Subject = model.Subject; var builder = new BodyBuilder(); builder.HtmlBody = model.Body; if (!(file == null)) { builder.Attachments.Add(file.FileName, file.FileBytes); } email.Body = builder.ToMessageBody(); using var smtp = new SmtpClient(); { smtp.Connect(_mailSettings.Host, _mailSettings.Port, SecureSocketOptions.StartTls); smtp.Authenticate(_mailSettings.Mail, _mailSettings.Password); smtp.Send(email); smtp.Disconnect(true); } }
public void SendEmail(EmailDto dto, FileSendEmail file = null) { var apiKey = _mailKeySettings; var client = new SendGridClient(apiKey); var from = new EmailAddress(_mailSettings.Mail); var to = new EmailAddress(dto.ToAddress); var pwd = GenerateToken(); var htmlContent = dto.Body; var textContent = ""; try { var message = MailHelper.CreateSingleEmail(from, to, dto.Subject, textContent, htmlContent); if (!(file == null)) { var sendFile = Convert.ToBase64String(file.FileBytes); message.AddAttachment(file.FileName, sendFile); } var response = client.SendEmailAsync(message); } catch (Exception) { throw; } }
public void SendEventTicket(Event eventU, User user) { _subscriptionService.CheckSubscription(eventU.CompanyId); var pdfBytes = GetEventTicket(eventU, user); var file = new FileSendEmail { FileBytes = pdfBytes, FileName = eventU.Name + "_Ticket.pdf" }; var generateEmail = new GenerateEmailDto { UrlAdress = _urlAdress + "/event/" + eventU.Id + "?", EmailMainText = "Your Ticket on Event", ObjectId = eventU.Id, Subject = "event ticket" }; var emailModel = _generateEmailWrapper.GenerateEmail(generateEmail, user); _emailWrapper.SendEmail(emailModel, file); }