public async Task SendConfirmUserEmailMessageAsync(User user, string confirmationToken) { var callbackUri = new Uri(_webAppBaseUri, $"confirmemail?userId={user.Id}&token={confirmationToken}"); var bodyBuilder = new StringBuilder(); bodyBuilder.AppendLine("<html><body>"); bodyBuilder.AppendLine("<p>"); bodyBuilder.AppendLine("Dear student,<br/><br/>"); bodyBuilder.AppendLine("Please confirm your registration for the GUTS project of the college university PXL.<br/>"); bodyBuilder.AppendLine("You can do this by following the link below:<br/><br/>"); bodyBuilder.AppendLine($"<a href=\"{callbackUri.AbsoluteUri}\">{callbackUri.AbsoluteUri}</a><br/><br/>"); bodyBuilder.AppendLine($"If you did not register via {_webAppBaseUri.AbsoluteUri}, then you can just ignore this email.<br/>"); bodyBuilder.AppendLine("</p>"); bodyBuilder.AppendLine("</body></html>"); var message = new MailMessage { From = new MailAddress(_fromEmail), Subject = "Please confirm your registration", Body = bodyBuilder.ToString(), IsBodyHtml = true }; message.To.Add(new MailAddress(user.Email)); await _smtpClient.SendMailAsync(message); }
public async Task SendEmail(string receiverEmail, string sub, string body) { var email = new MailMessage(new MailAddress("*****@*****.**", "SMP"), new MailAddress(receiverEmail)) { Subject = sub, Body = body, IsBodyHtml = true }; await _smtpClient.SendMailAsync(email); }
public async Task <bool> SendAsync(MailMessage message) { if (message.To.Count == 0) { throw new InvalidOperationException( "At least one \"To\" recipient must be defined for an email to be sent."); } if (!configuration.SendEmail) { Trace.TraceInformation("Email sending has been disabled."); return(false); } CleanMailAddressCollection(message.To); CleanMailAddressCollection(message.CC); CleanMailAddressCollection(message.Bcc); if (message.To.Count == 0) { Trace.TraceInformation("All \"To\" recipients have been removed; this email will not be sent."); return(false); } await smtpClient.SendMailAsync(message); return(true); }
protected override async Task Handle(Command request, CancellationToken cancellationToken) { var(subject, body) = await emailRenderingService.RenderAsync(request.ViewModel, request.Culture, request.SubjectKey); if (emailOptions.SubjectPrefix != null) { subject = emailOptions.SubjectPrefix + subject; } var message = new MimeMessage { Body = new TextPart(TextFormat.Html) { Text = body }, From = { new MailboxAddress(emailOptions.SenderName, emailOptions.SenderAddress) }, To = { new MailboxAddress(request.RecipientDisplayName, request.Recipient) }, Subject = subject }; if (!string.IsNullOrWhiteSpace(request.BccRecipient)) { message.Bcc.Add(new MailboxAddress(request.BccRecipient, request.BccRecipient)); } await smtpClient.SendMailAsync(message); }
public async Task <ServiceResult> SendMessageAsync(EmailType type, UserBaseDto userData, string appBasePath, Dictionary <string, string> additionalParameters = null) { var tokenCreateResult = await _tokenService.CreateAsync(TokenType.ViewInBrowserToken); var emailParameters = EmailParametersProvider.GetParameters(userData, additionalParameters); emailParameters.Add("ViewInBrowserLink", string.Format(appBasePath + TokenRedirectFormat, tokenCreateResult.Result.BuildEncryptedToken())); var messageDto = new MessageDto { Type = type }; var emailBody = _emailContentProvider.GetEmailBody(messageDto.Type, emailParameters); messageDto.To = userData.Email; messageDto.DisplayFrom = "Parking ATH"; messageDto.Title = _emailContentProvider.GetEmailTitle(messageDto.Type); messageDto.MessageParameters = JsonConvert.SerializeObject(emailParameters); messageDto.UserId = userData.Id; messageDto.From = _smtpSettings.From; messageDto.ViewInBrowserTokenId = tokenCreateResult.Result.Id; _messageRepository.Add(_mapper.Map <Message>(messageDto)); await _unitOfWork.CommitAsync(); var mailMessage = new MailMessage(messageDto.From, userData.Email, messageDto.Title, emailBody) { IsBodyHtml = true }; await _smtpClient.SendMailAsync(mailMessage); return(ServiceResult.Success()); }
/// <inheritdoc/> public async Task SendMailAsync(string subject, string message, params string[] emails) { if (!IsActive || string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(message) || emails.Length <= 0) { return; } var mail = new MailMessage { From = new MailAddress(_options.MailFrom, _options.MailFromName), Subject = subject, Body = message, BodyEncoding = Encoding.UTF8, IsBodyHtml = true, DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure }; foreach (var email in emails) { mail.To.Add(email); } SetupSmtpClient(_client, _options); await _client.SendMailAsync(mail); }
/// <summary> /// <inheritdoc cref="NotificationProvider.Send(MessageParameterCollection)"/> /// </summary> public override async Task <NotificationResult> Send(MessageParameterCollection messageParameters) { var emailMessage = new EmailMessage(messageParameters); // mail message var message = new MailMessage { Subject = emailMessage.Subject, Body = emailMessage.Body, IsBodyHtml = emailMessage.IsHtml }; if (!string.IsNullOrEmpty(emailMessage.FromAddress)) { message.From = new MailAddress(emailMessage.FromAddress); } else if (_smtpOptions != null && !string.IsNullOrEmpty(_smtpOptions.DefaultFromAddress)) { message.From = new MailAddress(_smtpOptions.DefaultFromAddress); } else { return(new NotificationResult(new List <string> { "From Address should not be empty" })); } foreach (var address in emailMessage.ToAddresses) { message.To.Add(new MailAddress(address)); } foreach (var address in emailMessage.CCAddresses) { message.CC.Add(new MailAddress(address)); } foreach (var address in emailMessage.BCCAddresses) { message.Bcc.Add(new MailAddress(address)); } // send email Logger.LogDebug(SmtpLogMessages.Sending_Start, emailMessage.Subject, emailMessage.ToAddresses); await _smtpClient.SendMailAsync(message); Logger.LogDebug(SmtpLogMessages.Sending_End, emailMessage.Subject, emailMessage.ToAddresses); return(new NotificationResult(true)); }
public async Task SendMail <T>(MailMessage <T> fsMailMessage) where T : class { var fsMailSettings = _fsMailOptions.Value; var message = new MailMessage(); message.To.AddRange(fsMailMessage.ToAddresses.ToArray()); message.From = new MailAddress(fsMailSettings.FromAddress); var subject = _stringInterpolationService.Interpolate(fsMailMessage.Subject, fsMailMessage.Model); var body = _stringInterpolationService.Interpolate(fsMailMessage.Body, fsMailMessage.Model); message.Subject = subject; message.Body = body; await _smtpClient.SendMailAsync(message); }
private async Task ProcessBlast(Template template, Customer customer, List <EmailRecipient> recipients, CancellationToken cancellationToken) { foreach (var recipient in recipients) { if (recipient.Email == null) { _logger.LogWarning($"Could not deliver email to recipient {recipient.Name}: no email address"); continue; } var mailMessage = new MailMessage("*****@*****.**", recipient.Email) { Body = await _templateEngine.MergeTemplate(template, customer, recipient, cancellationToken), IsBodyHtml = true }; await _smtpClient.SendMailAsync(mailMessage); } }
public async Task SendEmails(IEnumerable <string> to, string subject, string body, IDictionary <string, byte[]> attachments) { using var message = BuildMessage(to, subject, body, attachments); await _client.SendMailAsync(message); }