public async Task SendAwsSesEmail_Should_ThrowApplicationException_If_ToEmail_IsNull() { // Arrange var emailMessage = new EmailMessage("subject", "body", "from", ""); // Act & Assert await Assert.ThrowsAsync <ApplicationException>(() => _provider.SendEmail(emailMessage)); }
public async Task ProcessQueueMessage([ServiceBusTrigger("coursesignup", Connection = "ServiceBus")] string message, ILogger logger) { try { var command = Newtonsoft.Json.JsonConvert.DeserializeObject <CourseSignupCommand>(message); await CommandService.SignupCourse(command); //Email success - Mock data await EmailProvider.SendEmail("*****@*****.**", "Signup success!", "Success"); } catch (Exception ex) { //Log exception and Email failure await EmailProvider.SendEmail("*****@*****.**", "Signup failed!", "Failure"); } }
private async Task <bool> SendEmailToUser(ObjectId userId, Event eventDb, string scheduleId, CancellationToken cancellationToken) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == userId, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "eventTitle", eventDb.Title }, { "valuateUrl", _options.Value.SiteUrl + $"/configuracoes/avaliar-evento/{eventDb.Id}/{scheduleId}/" } } }; await _provider.SendEmail(emailData, "Avaliação de Evento", "BTG-EventStudentValuation"); await SaveNotification(user.Id, eventDb, scheduleId, true); return(true); } return(false); } catch (Exception ex) { await SaveNotification(user.Id, eventDb, scheduleId, false); return(false); } }
void SendSystemEmail(VLSystemEmail pendingEmail) { IEmailProvider provider = GetProvider(); InfoFormat("TheSystemMailer({0})::SendSystemEmail(), called for EmailId={1} & Subject={2} & ToAddress={3}", this.Name, pendingEmail.EmailId, pendingEmail.Subject, pendingEmail.ToAddress); var subject = pendingEmail.Subject; var body = pendingEmail.Body; MailAddress from = new MailAddress(pendingEmail.FromAddress, pendingEmail.FromDisplayName, Encoding.UTF8); MailAddress to = new MailAddress(pendingEmail.ToAddress); MailAddress replyTo = new MailAddress(pendingEmail.FromAddress); bool emailed = provider.SendEmail(from, to, replyTo, subject, Encoding.UTF8, body, Encoding.UTF8, false); if (emailed == false) { DebugFormat("Sending email to {0} (EmailId = {1}, subject = {2})-> FAILED", pendingEmail.ToAddress, pendingEmail.EmailId, pendingEmail.Subject); pendingEmail.Status = EmailStatus.Failed; pendingEmail.Error = "provider.SendEmail() returned false!"; pendingEmail.SendDT = Utility.UtcNow(); return; } DebugFormat("Sending email to {0} (EmailId = {1}, subject = {2})-> SUCCESS", pendingEmail.ToAddress, pendingEmail.EmailId, pendingEmail.Subject); pendingEmail.Status = EmailStatus.Sent; pendingEmail.SendDT = Utility.UtcNow(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IConfiguration configuration, IGreeter greeter, IEmailProvider emailProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseMvc(routes => { //routes.MapRoute( // name:"about-route", // template:"about", // defaults: new { controller = "About", action = "Address" } //); routes.MapRoute( name: "default", template: "{controller=Home}/{action=index}/{id?}" ); }); app.Run(async(context) => { //var greeting = configuration["Greeting"]; var emailSender = emailProvider.SendEmail(); // string greeting = greeter.GetMessageToPrint(); await context.Response.WriteAsync(emailSender.ToString()); }); }
public async Task <bool> SendNewsletter(int postId) { var post = await _db.Posts.AsNoTracking().Where(p => p.Id == postId).FirstOrDefaultAsync(); if (post == null) { return(false); } var subscribers = await _db.Subscribers.AsNoTracking().ToListAsync(); if (subscribers == null || subscribers.Count == 0) { return(false); } var settings = await _db.MailSettings.AsNoTracking().FirstOrDefaultAsync(); if (settings == null || settings.Enabled == false) { return(false); } string subject = post.Title; string content = post.Content.MdToHtml(); bool sent = await _emailProvider.SendEmail(settings, subscribers, subject, content); bool saved = await SaveNewsletter(postId, sent); return(sent && saved); }
private async Task <bool> SendEmail(ObjectId userId, CustomEmail message, List <string> variables, List <string> variablesToLower, CancellationToken cancellationToken) { var user = await GetUser(userId, cancellationToken); if (user != null && !string.IsNullOrEmpty(user.Email)) { var text = GetEmailText(user, message.Text, variables, variablesToLower); try { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "title", message.Title }, { "text", text } } }; await _provider.SendEmail(emailData, message.Title, "BTG-CustomEmail"); await SaveNotification(user.Id, message.Title, true); return(true); } catch (Exception ex) { return(false); } } return(false); }
public override async Task Process(IActionHelper actionHelper, IEmailProvider emailProvider, FormAnswers formAnswers) { var message = new EmailMessage( this.Properties.Subject, this.Properties.Content, this.Properties.From, actionHelper.GetEmailToAddresses(this, formAnswers)); await emailProvider.SendEmail(message); }
public async Task <Result> Handle(Contract request, CancellationToken cancellationToken) { BuildTemplates(); foreach (var key in this.emails.Keys) { var emailData = this.emails[key]; emailData.Email = request.email; await _provider.SendEmail(emailData, $"Test {key}", key); } return(Result.Ok()); }
private static void RepeatUntilStopped(IEmailProvider smtpProvider) { var fromEmail = string.Empty; var displayName = string.Empty; var isBodyHtml = false; var subject = string.Empty; var body = string.Empty; var stop = false; List <string> recipients = null; while (!stop) { var tempFromEmail = GetUserInputInline("Please enter the from email: "); fromEmail = string.IsNullOrWhiteSpace(tempFromEmail) ? fromEmail : tempFromEmail; var tempDisplayName = GetUserInputInline("Please enter your display name, or leave blank: "); displayName = string.IsNullOrWhiteSpace(tempDisplayName) ? displayName : tempDisplayName; var isBodyHtmlInput = GetYesNoInput("Is the body of the email html? (y/n): "); isBodyHtml = isBodyHtmlInput == null ? isBodyHtml : isBodyHtmlInput.Value; var tempSubject = GetUserInputInline("Please enter the subject of the email: "); subject = string.IsNullOrWhiteSpace(tempSubject) ? subject : tempSubject; Console.WriteLine("Please enter the body of the email below: "); var tempBody = Console.ReadLine(); body = string.IsNullOrWhiteSpace(tempBody) ? body : tempBody; Console.WriteLine("Please enter the recipient list separated by a comma (,) : "); var recipientListString = Console.ReadLine(); recipients = string.IsNullOrWhiteSpace(recipientListString) ? recipients : recipientListString?.Split(",").ToList(); var email = new EmailRequest() { FromEmail = fromEmail, Body = body, Subject = subject, Recipients = recipients, DisplayName = displayName, IsHtml = isBodyHtml }; var result = smtpProvider.SendEmail(email); Console.WriteLine($"Success: {result.Success}"); if (!result.Success) { Console.WriteLine($"Error Message: {result.ErrorMessage}"); } stop = !GetYesNoInput("Would you like to send another email? (y/n): ") ?? true; } }
private async Task <bool> SendEmailToQuestioner(ForumQuestion question, CancellationToken cancellationToken) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == question.CreatedBy, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); var moduleQry = await _db.ModuleCollection.FindAsync(m => m.Id == question.ModuleId, cancellationToken : cancellationToken); var module = await moduleQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null && module != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "forumTitle", question.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{question.ModuleId}/{question.Id}" } } }; await _provider.SendEmail(emailData, "Responderam sua pergunta", "BTG-ForumQuestionAnswered"); await SaveNotification(user.Id, module, question.Id, true); return(true); } return(false); } catch (Exception ex) { await SaveNotification(user.Id, module, question.Id, false); return(false); } }
private async Task <bool> SendEmail(User user, string password, CancellationToken token) { try { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "token", password }, { "username", user.UserName }, { "siteurl", _configuration[$"DomainOptions:SiteUrl"] }, { "studentmanual", _configuration[$"DomainOptions:StudentManual"] }, { "platformtutorial", _configuration[$"DomainOptions:PlatformTutorial"] } } }; await _provider.SendEmail( emailData, "Seja bem-vindo à Academia!", "BTG-NewUserMessage" ); return(true); } catch (Exception error) { await CreateErrorLog( "new-user-mail", JsonConvert.SerializeObject(error), token ); return(false); } }
public ActionResult Index(EmailModel model) { if (ModelState.IsValid) { _emailProvider.SendEmail(model); model.isValid = true; return(View(model)); } else { model.isValid = false; } return(View(model)); }
/// <summary> /// Sends the email via the respective provider mentioned in provider settings and updates the history and quota tables. /// </summary> /// <param name="email"><see cref="Email"/> model</param> public void SendEmail(Email email) { _logger.LogInformation($"SendEmail method hit."); string sender = string.Empty; string message = email.GetMessage(_emailTemplateInteractor); _logger.LogInformation($"Message: {message}"); // If external application didnot send the sender value, get it from template. if (string.IsNullOrEmpty(email.Sender)) { sender = email.GetSender(_emailTemplateInteractor); } else { sender = email.Sender; } if (string.IsNullOrEmpty(sender)) { sender = _emailProviderConnectionString.Fields["Sender"]; } _logger.LogInformation($"Sender: {sender}"); string emailResponseStatus = _emailProvider.SendEmail(email.Recipients, message, email.Subject, sender).Result; _logger.LogDebug($"Email response status: {emailResponseStatus}"); foreach (var recipient in email.Recipients) { var emailObj = new EmailHistoryDto() { MessageSent = message, Sender = sender, Recipients = recipient, TemplateName = email.TemplateName, TemplateVariant = email.Variant, ChannelKey = email.ChannelKey, ProviderName = email.ProviderName, Tags = email.Tag, SentOn = DateTime.UtcNow, Status = emailResponseStatus, Attempts = 1, }; _emailHistoryInteractor.AddEmailHistory(emailObj); } //Update Quota Implemented Outside The Loop--revisit _emailQuotaInteractor.UpdateEmailQuota(email.ChannelKey); }
public async Task <Result> Handle(Contract request, CancellationToken cancellationToken) { string siteUrl = _configuration[$"DomainOptions:SiteUrl"]; var userQry = await _db.UserCollection.FindAsync(u => u.UserName == request.Username, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); if (user == null) { return(Result.Fail("Usuário não encontrado")); } var token = await _userManager.GeneratePasswordResetTokenAsync(user); var randomPassword = Guid.NewGuid().ToString("d").Substring(1, 6); var pass = await _userManager.ResetPasswordAsync(user, token, randomPassword); if (!pass.Succeeded) { return(Result.Fail("Não foi possivel resetar a senha")); } var tokenResource = await _tokenGenerator.GenerateUserToken(user); await SaveRefreshToken(user.Id, tokenResource.RefreshToken, cancellationToken); var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.UserName }, { "token", randomPassword }, { "siteurl", siteUrl } } }; await _provider.SendEmail(emailData, "Esqueci minha senha", "BTG-ForgotPasswordTemplate"); return(Result.Ok()); }
private async Task <bool> SendActivationCode(User user, UserVerificationEmail email) { try { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "nome", user.Name }, { "code", email.Code } } }; await _provider.SendEmail(emailData, "Código de autenticação", "BTG-UserActivationCode"); return(true); } catch (Exception err) { return(false); } }
private async Task <bool> SendEmailModuleInstructor(ForumQuestion forumQuestion, CancellationToken cancellationToken) { var moduleQry = await _db.ModuleCollection.FindAsync(m => m.Id == forumQuestion.ModuleId, cancellationToken : cancellationToken); var module = await moduleQry.SingleOrDefaultAsync(cancellationToken); if (module != null && module.InstructorId != null && module.InstructorId != ObjectId.Empty) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == module.InstructorId, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "forumTitle", forumQuestion.Title }, { "moduleName", module.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{forumQuestion.ModuleId}/{forumQuestion.Id}" } } }; await _provider.SendEmail(emailData, "Uma pergunta foi feita no modulo que você é o instrutor", "BTG-ForumQuestionInstructor"); await SaveNotification(user.Id, module, forumQuestion.Id, true, "Nova pergunta no modulo que você é o instrutor"); } } catch (Exception ex) { await SaveNotification(user.Id, module, forumQuestion.Id, false, "Nova pergunta no modulo que você é o instrutor"); } } if (module != null && module.TutorsIds != null && module.TutorsIds.Count > 0) { foreach (ObjectId tutorId in module.TutorsIds) { if (tutorId != null && tutorId != ObjectId.Empty) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == tutorId, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "forumTitle", forumQuestion.Title }, { "moduleName", module.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{forumQuestion.ModuleId}/{forumQuestion.Id}" } } }; await _provider.SendEmail(emailData, "Uma pergunta foi feita no modulo que você é o tutor", "BTG-ForumQuestionInstructor"); await SaveNotification(user.Id, module, forumQuestion.Id, true, "Nova pergunta no modulo que você é o tutor"); } } catch (Exception ex) { await SaveNotification(user.Id, module, forumQuestion.Id, false, "Nova pergunta no modulo que você é o tutor"); } } } } if (module != null && module.ExtraInstructorIds != null && module.ExtraInstructorIds.Count > 0) { foreach (ObjectId InstructorId in module.ExtraInstructorIds) { if (InstructorId != null && InstructorId != ObjectId.Empty) { var userQry = await _db.UserCollection.FindAsync(u => u.Id == InstructorId, cancellationToken : cancellationToken); var user = await userQry.SingleOrDefaultAsync(cancellationToken); try { if (user != null) { var emailData = new EmailUserData { Email = user.Email, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.Name }, { "forumTitle", forumQuestion.Title }, { "moduleName", module.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{forumQuestion.ModuleId}/{forumQuestion.Id}" } } }; await _provider.SendEmail(emailData, "Uma pergunta foi feita no modulo que você é o tutor", "BTG-ForumQuestionInstructor"); await SaveNotification(user.Id, module, forumQuestion.Id, true, "Nova pergunta no modulo que você é o tutor"); } } catch (Exception ex) { await SaveNotification(user.Id, module, forumQuestion.Id, false, "Nova pergunta no modulo que você é o tutor"); } } } } var forumEmailUsers = _db.UserCollection.AsQueryable().Where(u => u.ForumActivities.HasValue && u.ForumActivities.Value).ToList(); try { if (forumEmailUsers != null && forumEmailUsers.Count > 0) { var activeUser = _db.UserCollection.AsQueryable().FirstOrDefault(u => u.Id == forumQuestion.CreatedBy); if (activeUser != null) { foreach (User user in forumEmailUsers) { if (user != null && (!string.IsNullOrEmpty(user.ForumEmail) || !string.IsNullOrEmpty(user.Email))) { var emailToSend = string.IsNullOrEmpty(user.ForumEmail) ? user.Email : user.ForumEmail; var emailData = new EmailUserData { Email = emailToSend, Name = user.Name, ExtraData = new Dictionary <string, string> { { "name", user.UserName }, { "username", activeUser.Name }, { "forumTitle", forumQuestion.Title }, { "forumUrl", _options.Value.SiteUrl + $"/forum/{module.Title}/{forumQuestion.ModuleId}/{forumQuestion.Id}" } } }; await _provider.SendEmail(emailData, "Uma atividade no módulo " + module.Title, "BTG-ForumActivity"); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
public bool Post(EmailModel model) { return(_emailProvider.SendEmail(model)); }
/// <summary> /// Sends the help request. /// #6 /// </summary> /// <param name="ticket">The ticket.</param> /// <param name="isPublicEmail">if set to <c>true</c> [is public email or if Kerb email].</param> /// <param name="emailProvider">The email provider.</param> public void SendHelpRequest(Ticket ticket, bool isPublicEmail, IEmailProvider emailProvider) { Check.Require(ticket != null, "Details are missing."); var supportEmail = GetHelpEmail(ticket); var fromEmail = ""; if (isPublicEmail) { fromEmail = ticket.FromEmail; } else { Check.Require(ticket.User != null, "Login Details missing."); fromEmail = ticket.User.Email; } Check.Require(!string.IsNullOrEmpty(fromEmail), "Email details missing."); Check.Require(!string.IsNullOrEmpty(supportEmail), "Help Desk Email address not supplied."); MailMessage message = new MailMessage(fromEmail, supportEmail, ticket.Subject, BuildBody(ticket)); foreach (var emailCC in ticket.EmailCCs) { if (!FilterCruEmail(emailCC)) { message.CC.Add(emailCC); } } foreach (var attachment in ticket.Attachments) { var messStream = new MemoryStream(attachment.Contents); var messAttach = new Attachment(messStream, attachment.FileName, attachment.ContentType); message.Attachments.Add(messAttach); } message.IsBodyHtml = false; emailProvider.SendEmail(message); }
public IActionResult Test() { var emailMessage = _emailProvider.SendEmail(); return(Ok(emailMessage)); }
void SendMails(VLSurvey survey, VLCollector collector, VLMessage message) { IEmailProvider provider = GetProvider(); int totalRows = 0, pageIndex = 1, pageSize = 20; var fromDisplayName = SystemManager.GetSystemParameterByKey("@FromDisplayName"); if (fromDisplayName == null) { throw new VLException("SystemParameters: @FromDisplayName undefined"); } InfoFormat("TheMailler({0})::SendMails(), called for messageid={1} & subject={2}", this.Name, message.MessageId, message.Subject); /*διαβάζουμε σελίδα - σελίδα όλα τα messageRecipients για αυτό το message:*/ var recipients = SurveyManager.GetRecipientsForMessage(message, pageIndex++, pageSize, ref totalRows); while (recipients.Count > 0) { foreach (var recipient in recipients) { #region loop each recipient and send the email: //Εχουμε έναν Recipient: VLMessageRecipient messageRecipient = null; try { messageRecipient = SurveyManager.GetMessageRecipientById(message.MessageId, recipient.RecipientId); if (messageRecipient == null) { throw new VLException(string.Format("There is no MessageRecipient for messageId={0} and recipient!d={1}", message.MessageId, recipient.RecipientId)); } messageRecipient.SendDT = Utility.UtcNow(); /*Οσα Recipients έχουν γίνει OptedOut δεν τα στέλνουμε:*/ if (recipient.IsOptedOut) { DebugFormat("Sending email to {0} (messageId = {1}, recipient = {2})-> FAILED (IsOptedOut)", recipient.Email, message.MessageId, recipient.RecipientId); message.SkipCounter++; messageRecipient.ErrorCount++; messageRecipient.Status = MessageRecipientStatus.OptedOut; continue; } /*Οσα Recipients έχουν γίνει Bounced, δεν τα στέλνουμε:*/ if (recipient.IsBouncedEmail) { DebugFormat("Sending email to {0} (messageId = {1}, recipient = {2})-> FAILED (IsBouncedEmail)", recipient.Email, message.MessageId, recipient.RecipientId); message.SkipCounter++; messageRecipient.ErrorCount++; messageRecipient.Status = MessageRecipientStatus.Bounced; continue; } /*Στέλνουμε μόνο όσα είναι σε status Pending:*/ if (messageRecipient.Status != MessageRecipientStatus.Pending) { message.SkipCounter++; continue; } //TODO: //Ελεγχος για τα QUOTAS του Πελάτη if (collector.UseCredits && collector.CreditType.HasValue && collector.CreditType.Value == CreditType.EmailType) { #region Πραγματοποιούμε την ΧΡΕΩΣΗ για αυτό το email που πρόκειται να στείλουμε: bool charged = false; if (messageRecipient.CollectorPayment.HasValue) { charged = SystemManager.ChargePaymentForEmail(messageRecipient.CollectorPayment.Value, collector.CollectorId, message.MessageId, recipient.RecipientId); } else { charged = true; } if (charged == false) { DebugFormat("Sending email to {0} (messageId = {1}, recipient = {2})-> NoCredit", recipient.Email, message.MessageId, recipient.RecipientId); message.FailedCounter++; messageRecipient.ErrorCount++; messageRecipient.Status = MessageRecipientStatus.NoCredit; continue; } if (messageRecipient.CollectorPayment.HasValue) { messageRecipient.IsCharged = true; } #endregion } /* * ΑΠΟ ΕΔΩ ΚΑΙ ΚΑΤΩ ΕΧΟΥΜΕ ΧΡΕΩΣEI ΓΙΑ ΤΗΝ ΑΠΟΣΤΟΛΗ ΤΟΥ EMAIL. * ΓΙΑ ΑΥΤΟ ΕΑΝ ΣΥΜΒΕΙ ΚΑΤΙ ΦΡΟΝΤΙΖΟΥΜΕ ΝΑ ΞΕΧΡΕΩΣΟΥΜΕ, ΠΡΩΤΑ: */ try { /*Προετοιμάζουμε το body του μηνύματος, αντικαθιστώντας τυχόν placeholders:*/ var subject = message.Subject; var body = message.Body; body = body.Replace("[SurveyLink]", Utility.GetSurveyRuntimeURL(survey, collector, recipient)); body = body.Replace("[RemoveLink]", Utility.GetRemoveRecipientURL(survey, collector, message, recipient)); var displayName = string.Format("{0} via {1}", message.Sender, fromDisplayName.ParameterValue); MailAddress from = new MailAddress(message.Sender, displayName, Encoding.UTF8); MailAddress to = new MailAddress(recipient.Email); MailAddress replyTo = new MailAddress(message.Sender); bool emailed = provider.SendEmail(from, to, replyTo, subject, Encoding.UTF8, body, Encoding.UTF8, false); if (emailed == false) { DebugFormat("Sending email to {0} (messageId = {1}, recipient = {2})-> FAILED", recipient.Email, message.MessageId, recipient.RecipientId); message.FailedCounter++; messageRecipient.ErrorCount++; messageRecipient.Status = MessageRecipientStatus.Failed; messageRecipient.Error = "provider.SendEmail() returned false!"; continue; } DebugFormat("Sending email to {0} (messageId = {1}, recipient = {2})-> SUCCESS", recipient.Email, message.MessageId, recipient.RecipientId); message.SentCounter++; messageRecipient.ErrorCount = 0; messageRecipient.Status = MessageRecipientStatus.Sent; } catch { if (collector.CreditType.HasValue && collector.CreditType.Value == CreditType.EmailType) { #region Ξεχρεώνουμε if (messageRecipient.CollectorPayment.HasValue && messageRecipient.IsCharged) { bool uncharged = SystemManager.UnchargePaymentForEmail(messageRecipient.CollectorPayment.Value, collector.CollectorId, message.MessageId, recipient.RecipientId); if (uncharged) { messageRecipient.IsCharged = false; } } #endregion } throw; } } catch (Exception ex) { this.Error(string.Format("Sending email to {0} (messageId = {1}, recipient = {2})-> Exception", recipient.Email, message.MessageId, recipient.RecipientId), ex); message.FailedCounter++; if (messageRecipient != null) { messageRecipient.ErrorCount++; messageRecipient.Status = MessageRecipientStatus.Failed; messageRecipient.Error = Utility.UnWindExceptionContent(ex); } } finally { if (messageRecipient != null) { try { messageRecipient = SurveyManager.UpdateMessageRecipient(messageRecipient); if (messageRecipient.Status == MessageRecipientStatus.Sent) { /*το email, στάλθηκε, πρέπει να ενημερώσουμε και το Recipient:*/ if (recipient.IsSentEmail == false) { recipient.IsSentEmail = true; var updatedRecipient = SurveyManager.UpdateRecipientIntl(recipient); } } } catch (Exception innerEx) { this.Error(string.Format("TheMailler::SendMails():finally"), innerEx); } } } #endregion } recipients = SurveyManager.GetRecipientsForMessage(message, pageIndex++, pageSize, ref totalRows); } provider.Dispose(); }
public void SendEmail(string emailAddress, string password, string message) { emailProvider?.RegisterUser(emailAddress, message); emailProvider?.SendEmail(emailAddress, message); }