public void SendMail(string fromEmail, string toEmail, string ccEmail, string emailSubject, string emailBody, List <EmailAttachment> attachments) { using (MailMessage mailMessage = new MailMessage()) { MailAddress fromAddress = new MailAddress(fromEmail.Trim()); if (null != toEmail && toEmail.Contains(";")) { foreach (var email in toEmail.Split(';')) { mailMessage.To.Add(new MailAddress(email.Trim())); } } else if (null != toEmail) { mailMessage.To.Add(new MailAddress(toEmail.Trim())); } mailMessage.From = fromAddress; if (null != ccEmail && ccEmail.Trim() != "") { foreach (var email in ccEmail.Split(';')) { mailMessage.CC.Add(new MailAddress(email.Trim())); } } mailMessage.Subject = emailSubject.Trim(); mailMessage.IsBodyHtml = true; mailMessage.Body = emailBody.Trim(); List <MemoryStream> streams = new List <MemoryStream>(); if (attachments != null && attachments.Count > 0) { foreach (var attachment in attachments) { var stream = new MemoryStream(attachment.Data); streams.Add(stream); mailMessage.Attachments.Add(new Attachment(stream, attachment.Name)); } } smtpClient.Send(mailMessage); foreach (var s in streams) { try { s.Dispose(); } catch { } } } }
public RedirectToRouteResult ResetPassword(Guid id) { var user = _userService.Get(id); var newPassword = _passwordService.ResetPassword(user); var body = ResetPasswordBody + newPassword; _smtpClient.Send(new MailMessage(ResetPasswordFromAddress, user.Email, ResetPasswordSubject, body)); return(RedirectToAction("Password", new { id })); }
public RedirectToRouteResult ResetPassword(Guid id) { var user = _userService.Get(id); var newPassword = _passwordService.ResetPassword(user); var body = string.Format(ResetPasswordBody, new string[] { user.UserName, newPassword, Request.Url.GetLeftPart(UriPartial.Authority) }); _smtpClient.Send(new MailMessage(ResetPasswordFromAddress, user.Email, ResetPasswordSubject, body)); TempData.AddInfo(Resources.Messages.ActionSuccess); return(RedirectToAction("Password", new { id })); }
public void SendPasswordByEmail(UserDto user, string password) { EmailMessage messageToSend = new EmailMessage { FullName = user.Name + ' ' + user.LastName, Email = user.Email, Subject = "Contraseña de acceso Grupo Angular!" }; messageToSend.Body.SubMimeType = ConstsEmail.SUB_MIMETYPE_HTML; messageToSend.Body.Text = GenerateHTMLPassWord(password); _smtpClient.Send(messageToSend); }
public RedirectToRouteResult ResetPassword(Guid id) { var user = _userService.Get(id); var newPassword = _passwordService.ResetPassword(user); var body = ResetPasswordBody + newPassword; var msg = new MailMessage(); msg.To.Add(user.Email); msg.Subject = ResetPasswordSubject; msg.Body = body; _smtpClient.Send(msg); return(RedirectToAction("Password", new { id })); }
public void SendEmail(string to, string content) { if (string.IsNullOrEmpty(content) || !IsValidEmail(to)) { throw new NullReferenceException("parameters to and content are required!"); } var message = new MailMessage(_emailSettings.Sender, to) { Subject = _emailSettings.Subject, Body = HtmlHelper.GetHtmlBody(content, "Questions"), IsBodyHtml = true }; _smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; _smtpClient.PickupDirectoryLocation = _emailSettings.LocalDirectoryPath; try { _smtpClient.Send(message); } catch (Exception) { throw; } }
public void Send(string to, string subject, string html, string from = null) { // create message var email = new MimeMessage(); email.From.Add(MailboxAddress.Parse(from ?? _appSettings.EmailFrom)); email.To.Add(MailboxAddress.Parse(to)); email.Subject = subject; email.Body = new TextPart(TextFormat.Html) { Text = html }; // send email _smtpClient.Connect(_appSettings.SmtpHost, _appSettings.SmtpPort, _appSettings.SmtpTls ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto); try { if (!string.IsNullOrWhiteSpace(_appSettings.SmtpUser)) { _smtpClient.Authenticate(_appSettings.SmtpUser, _appSettings.SmtpPass); } _smtpClient.Send(email); } finally { _smtpClient.Disconnect(true); } }
public RedirectToRouteResult ResetLogonPassword(String email) { if (!string.IsNullOrWhiteSpace(email)) { if (email.Contains("@")) { var user = _userService.Get(email); if (user != null) { var newPassword = _passwordService.ResetPassword(user); var body = ResetPasswordBody + newPassword; var msg = new MailMessage(); msg.To.Add(user.Email); msg.Subject = ResetPasswordSubject; msg.Body = body; _smtpClient.Send(msg); return(RedirectToAction("ResetPasswordEmailConfirmed")); } } } return(RedirectToAction("CannotFindLogon", new { email })); }
public void Send(IMessageProvider messageProvider, string receiverString) { _message.Subject = messageProvider.GetAbstract(); _message.Body = messageProvider.GetText(); _message.ToFromString(receiverString); _smtpClient.Send(_message); }
public void Send <T>(string emailAddress, T model) { string subject = _emailSubjectRenderer.Render(model); string body = _emailBodyRenderer.Render(model); _smtpClient.Send(emailAddress, subject, body); }
public void Send(MailMessage mailMessage, Markdown markdownGenerator) { if (smtpClient.DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory && !Directory.Exists(smtpClient.PickupDirectoryLocation)) { Directory.CreateDirectory(smtpClient.PickupDirectoryLocation); } if (markdownGenerator == null) { markdownGenerator = new Markdown(); } string markdownBody = mailMessage.Body; string htmlBody = markdownGenerator.Transform(markdownBody); AlternateView textView = AlternateView.CreateAlternateViewFromString( markdownBody, null, MediaTypeNames.Text.Plain); mailMessage.AlternateViews.Add(textView); AlternateView htmlView = AlternateView.CreateAlternateViewFromString( htmlBody, null, MediaTypeNames.Text.Html); mailMessage.AlternateViews.Add(htmlView); smtpClient.Send(mailMessage); }
public void Send(MailMessage mailMessage) { _validator.Validate(mailMessage); ISmtpClient client = null; try { client = _factory.Create(); SetUpClient(client); client.Send(mailMessage); } catch (ArgumentException e) { throw new SmptClientException("Cannot setup client.", e); } catch (InvalidOperationException e) { throw new SmptClientException("Client cannot do operation.", e); } catch (SmtpException e) { throw new SmptClientException("Client cannot send mail message.", e); } finally { client?.Dispose(); } }
/// <summary> /// Sends a MailMessage using smtpClient /// </summary> /// <param name="message">The mailMessage Object</param> /// <param name="smtpClient">leave null to use default System.Net.Mail.SmtpClient</param> public static void Send(this MailMessage message, ISmtpClient smtpClient = null) { smtpClient = smtpClient ?? GetSmtpClient(); using (smtpClient) { smtpClient.Send(message); } }
public void Send(MailMessage mailMessage, MarkdownPipeline pipeline) { if (smtpClient.DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory && !Directory.Exists(smtpClient.PickupDirectoryLocation)) { Directory.CreateDirectory(smtpClient.PickupDirectoryLocation); } if (pipeline == null) { pipeline = new MarkdownPipelineBuilder() .UseSoftlineBreakAsHardlineBreak() .UseAdvancedExtensions() .Build(); } string markdownBody = mailMessage.Body; string htmlBody = Markdown.ToHtml(markdownBody, pipeline); AlternateView textView = AlternateView.CreateAlternateViewFromString( markdownBody, null, MediaTypeNames.Text.Plain); mailMessage.AlternateViews.Add(textView); AlternateView htmlView = AlternateView.CreateAlternateViewFromString( htmlBody, null, MediaTypeNames.Text.Html); mailMessage.AlternateViews.Add(htmlView); smtpClient.Send(mailMessage); }
public ActionResult EmailTest(string emailTo) { ViewBag.emailTo = emailTo; StringBuilder sb = new StringBuilder(); sb.Append("</body>"); sb.Append("<h3>"); sb.Append(" <p width='80%' align='center' cellpadding='100' cellspacing='100'>"); sb.Append(" Email Test"); sb.Append(" </p>"); sb.Append("</h3>"); sb.Append("</body>"); MailMessage mm = new MailMessage() { Subject = "Email Test - goSSRA", IsBodyHtml = true, Body = sb.ToString() }; // Add CC Recipients if (!String.IsNullOrEmpty(emailTo)) { mm.To.Add(emailTo); mm.CC.Add("*****@*****.**"); _smtpClient.Send(mm); } return(RedirectToAction("CheckEmail", new { emailTo })); }
/// <summary> /// Sends a MailMessage using smtpClient /// </summary> /// <param name="smtpClient">leave null to use default System.Net.Mail.SmtpClient</param> public virtual void Send(ISmtpClient smtpClient = null) { smtpClient = smtpClient ?? GetSmtpClient(); using (smtpClient) { smtpClient.Send(this); } }
public void SendSupportMail(string toAddress) { if (IsValid(toAddress)) { MailMessage message = MakeMessage(toAddress); smtpClient.Send(message); } }
/// <summary> /// Create mail and send with SMTP /// </summary> /// <param name="events">event printed in the body of the event</param> private void ProcessSingleMailMessage([NotNull] List <AsyncLogEventInfo> events) { try { if (events.Count == 0) { throw new NLogRuntimeException("We need at least one event."); } LogEventInfo firstEvent = events[0].LogEvent; LogEventInfo lastEvent = events[events.Count - 1].LogEvent; // unbuffered case, create a local buffer, append header, body and footer var bodyBuffer = CreateBodyBuffer(events, firstEvent, lastEvent); using (var msg = CreateMailMessage(lastEvent, bodyBuffer.ToString())) { using (ISmtpClient client = this.CreateSmtpClient()) { if (!UseSystemNetMailSettings) { ConfigureMailClient(lastEvent, client); } else { ConfigureFrom(); } InternalLogger.Debug("Sending mail to {0} using {1}:{2} (ssl={3})", msg.To, client.Host, client.Port, client.EnableSsl); InternalLogger.Trace(" Subject: '{0}'", msg.Subject); InternalLogger.Trace(" From: '{0}'", msg.From.ToString()); client.Send(msg); foreach (var ev in events) { ev.Continuation(null); } } } } catch (Exception exception) { //always log InternalLogger.Error(exception, "Error sending mail."); if (exception.MustBeRethrown()) { throw; } foreach (var ev in events) { ev.Continuation(exception); } } }
public async Task SendEmailAsync(string email, string subject, string htmlMessage) { MailMessage mailMessage = new MailMessage(_from, new MailAddress(email)); mailMessage.Body = htmlMessage; mailMessage.Subject = subject; await _client.Send(mailMessage, _settings); }
/// <summary> /// Sends the messages which match the filters and applies the overrides prior to sending /// </summary> /// <param name="filters"></param> /// <param name="overrides"></param> /// <param name="audit">whether to change the sent status and number of tries for an email</param> /// <returns></returns> public IEnumerable <DequeueResultItem> SendQueuedMessages(DequeueFilterList filters, OverrideList overrides, bool audit = true) { if (filters == null) { throw new ArgumentNullException("filters"); } if (overrides == null) { throw new ArgumentNullException("overrides"); } TroutLog.Log.Info(string.Format("Beginning dequeuing with{0} auditing at", audit ? "" : "out")); List <DequeueResultItem> results = new List <DequeueResultItem>(); var messages = filters.Filter(Repository); foreach (var message in messages.ToList()) { MailMessage mailMessage = GetMailMessage(message, overrides); foreach (var attachment in AttachmentFileSystem.GetAttachments(message)) { mailMessage.Attachments.Add(attachment); } var result = SmtpClient.Send(mailMessage); results.Add(new DequeueResultItem(message, result.IsSuccess, result.Message, mailMessage, result.Tries)); TroutLog.Log.Info(string.Format("{0} was {1}sent with message - {2} after {3} tries.", message.ID, result.IsSuccess ? "" : "not ", result.Message, result.Tries)); if (audit) { if (result.IsSuccess) { message.IsSent = true; message.SendDate = DateTime.Now; } else { message.IsSent = false; message.SendDate = null; } message.NumberTries++; message.LastTryDate = DateTime.Now; } } TroutLog.Log.Info(string.Format("Saving of dequeue results")); Repository.SaveChanges(); return(results); }
public void The_sender_email_address_is_correct() { // When emailService.SendEmail(EmailTestHelper.GetDefaultEmail()); // Then A.CallTo(() => smtpClient.Send( A <MimeMessage> .That.Matches(m => m.From.ToString() == "*****@*****.**" ),
//// TODO //// public Func<Email, MailMessage> CreateMailMessageFactory { get; set; } public void Send(Email email) { Invariant.IsNotNull(email, "email"); using (MailMessage message = CreateDefaultMailMessageFactory()(email)) { using (ISmtpClient client = CreateClientFactory()) { client.Send(message); } } }
public void Send(string fromAddress, string toAddress, string subject, string body) { var message = new MailMessage { From = new MailAddress(fromAddress) }; message.To.Add(toAddress); message.Subject = subject; message.Body = body; _smtpClient.Send(fromAddress, toAddress, subject, body); }
public void Send(EmailSettings emailSettings) { var mail = new MailMessage { Subject = emailSettings.Subject, Body = emailSettings.Body, From = new MailAddress(emailSettings.FromAddress, emailSettings.FromName) }; mail.To.Add(string.Join(",", emailSettings.EmailAddresses)); _smtpClient.Send(mail); }
public ActionResult Shipped([FromRoute] string orderId) { CreateConnection().Execute("update shipment set status = 2 where orderId = @orderId", new { orderId }); OrderDto order = GetOrderInternal(orderId); string email = CreateConnection().QueryFirst <string>("select email from client where id = @id", new { id = order.ClientId }); _smtpClient.Send("*****@*****.**", email, "Shipment confirmation", $"your order number : {order.Number} ha been shipped"); return(Ok()); }
private void SendEmail(string content) { if (content == null) { throw new FormatException(); } MailMessage mailMessage = new MailMessage(); mailMessage.Body = content; client.Send(mailMessage); }
public void Handle(SendNotificationCommand command) { string email = _emailRepository.GetEmail(command.LoginName); _smtpClient.Send(email, command.Title, command.Body); _notificationRepository.Add(email, command.Title, command.Body, _dateTimeProvider.Now(), command.LoginName, command.NotificationType); _eventBus.Publish(new NotificationSentEvent() { LoginName = command.LoginName, Email = email, NotificationType = command.NotificationType }); }
private void SendSingleEmailFromClient( Email email, string mailSenderAddress, ISmtpClient client ) { try { MimeMessage message = CreateMessage(email, mailSenderAddress); client.Send(message); } catch (Exception error) { logger.LogError(error, "Sending an email has failed"); } }
public RedirectToRouteResult ResetPassword(int id, string answer) { try { var user = _userService.Get(id); var newPassword = _passwordService.ResetPassword(user, answer); var body = ResetPasswordBody + newPassword; _smtpClient.Send(new MailMessage(ResetPasswordFromAddress, user.Email, ResetPasswordSubject, body)); } catch (MembershipPasswordException) { TempData["wrongPassword"] = "******"; } return(RedirectToAction("Details", new { id })); }
/// <summary> /// Invia il messaggio tramite il servizio SMTP. /// </summary> /// <param name="email"></param> /// <param name="hasToWait"></param> /// <returns>String.Empty tutto ok, messaggio di errore altrimenti</returns> public string Send(EmailMessage email, bool hasToWait = false) { var SEND_COPY_TO_DEVELOPER = string.Empty; // TODO: manda una copia del messaggio al developer (è una sorta di "inspect mode" da attivare per debug) if (client == null || email == null) { return("Client or EmailMessage not defined"); } try { var r = client.Send(email, hasToWait); return(r); } catch (Exception e) { return("SmtpClient exception: " + TextHelper.FormatException(e)); } }