public void SendMailFromModuleNotification(string istanceIdentifier, int idUser, string moduleCode, Notification.Domain.dtoModuleNotificationMessage message) { IstanceConfig istance = Config.GetIstanceConfiguration(istanceIdentifier); SmtpServiceConfig cfg = GetSmtpSettings(istanceIdentifier); if (cfg != null && istance != null) { using (ISession session = lm.Comol.Core.Data.SessionDispatcher.NewSession(istance.ConnectionString)) { if (session != null) { using (InternalMailService service = new InternalMailService(cfg, istance, session)) { Boolean result = false; String messagePath = service.GetAttachmentsFullPath(istance.AttachmentUploadPath, message.AttachmentPath); try { result = service.SendMail(idUser, moduleCode, message, (message.MailSettings.IsBodyHtml), messagePath, message.AttachmentSavedPath); } catch (Exception ex) { ErrorHandler.addMessageToPoisonQueue(ex, message); } } } else { ErrorHandler.addMessageToPoisonQueue(message); } } } }
public dtoMailMessagePreview(Int32 idUserLanguage, lm.Comol.Core.DomainModel.Language dLanguage, dtoMailMessage message, MessageSettings settings, SmtpServiceConfig smtpConfig) { IdUserLanguage = idUserLanguage; IdUserLanguage = (dLanguage == null) ? 0 : dLanguage.Id; Message = message; Settings = settings; SmtpConfig = smtpConfig; IsEmpty = false; }
//private MailException InternalSendMail(Int32 idUserLanguage, Language dLanguage, dtoMailMessage dtoMessage, Boolean replaceCRLF = false) //{ // try // { // MailMessage message = CreateMessage(idUserLanguage, dLanguage, dtoMessage, replaceCRLF); // SmtpClient smtpClient = CreateSmtpClient(); // List<dtoRecipients> recipients = new List<dtoRecipients>(); // dtoMessage.To.ForEach(t => recipients.Add(new dtoRecipients() { Mail = t, Type = RecipientType.To })); // dtoMessage.CC.ForEach(t => recipients.Add(new dtoRecipients() { Mail = t, Type = RecipientType.CC })); // dtoMessage.BCC.ForEach(t => recipients.Add(new dtoRecipients() { Mail = t, Type = RecipientType.BCC })); // Int32 maxRecipients = SMTPconfig.MaxRecipients; // int Total = recipients.Count; // int PageNumber = 0; // if (maxRecipients > 0) // { // if (recipients.Count / maxRecipients < 1) // PageNumber = 0; // else // PageNumber = (recipients.Count % maxRecipients == 0 ? recipients.Count / maxRecipients - 1 : (recipients.Count / maxRecipients)); // } // for (int i = 0; i <= PageNumber; i++) // { // List<dtoRecipients> paged = null; // if (SMTPconfig.MaxRecipients > 0) // paged = recipients.Skip(maxRecipients * i).Take(maxRecipients).ToList(); // else // paged = recipients; // if (paged != null && paged.Count > 0) // { // message.To.Clear(); // message.CC.Clear(); // message.Bcc.Clear(); // paged.Where(p => p.Type == RecipientType.To).ToList().ForEach(p => message.To.Add(p.Mail)); // paged.Where(p => p.Type == RecipientType.CC).ToList().ForEach(p => message.CC.Add(p.Mail)); // paged.Where(p => p.Type == RecipientType.BCC).ToList().ForEach(p => message.Bcc.Add(p.Mail)); // smtpClient.Send(message); // } // } // if (MailSettings.CopyToSender) // { // message.To.Clear(); // message.CC.Clear(); // message.Bcc.Clear(); // message.Subject = SubjectForCopy(idUserLanguage, dLanguage, dtoMessage); // message.To.Add(new MailAddress(SMTPconfig.System.Sender.Address, dtoMessage.FromUser.Address)); // smtpClient.Send(message); // } // return MailException.MailSent; // } // catch (ArgumentOutOfRangeException outOfRangeException) // { // return MailException.NoDestinationAddress; // } // catch (SmtpException smtpException) // { // return MailException.SMTPunavailable; // } // catch (Exception ex) // { // return MailException.UnknownError; // } //} private SmtpClient CreateSmtpClient(SmtpServiceConfig config) { SmtpClient smtpClient = new SmtpClient(config.Host, config.Port); smtpClient.EnableSsl = config.Authentication.EnableSsl; if (config.Authentication.Enabled) { smtpClient.Credentials = new System.Net.NetworkCredential(config.Authentication.AccountName, config.Authentication.AccountPassword); } return(smtpClient); }
public void SendMessage(SmtpServiceConfig smtpConfig, List <lm.Comol.Core.Mail.Messages.dtoMailTranslatedMessage> messages) { if (UserContext.isAnonymous) { View.CurrentMode = Domain.EditMessageMode.None; } else { if (messages == null) { View.DisplayUnableToSendMessage(); } else { List <dtoTemplateTranslation> translations = View.CurrentTranslations; List <lm.Comol.Core.Mail.Messages.dtoBaseMessageRecipient> rSkipped = new List <lm.Comol.Core.Mail.Messages.dtoBaseMessageRecipient>(); lm.Comol.Core.Mail.Messages.dtoBaseMailTemplate template = new lm.Comol.Core.Mail.Messages.dtoBaseMailTemplate(View.CurrentSettings); template.IdTemplate = View.IdSelectedTemplate; TemplateDefinitionVersion version = null; if (View.IdSelectedVersion > 0 || template.IdTemplate > 0) { version = Service.GetVersion(template.IdTemplate, View.IdSelectedVersion); } if (version != null) { template.IdVersion = version.Id; template.IsTemplateCompliant = IsTemplateCompliant(translations, version); } else { template.IsTemplateCompliant = false; } if (!template.IsTemplateCompliant) { template.DefaultTranslation = (translations.Where(t => t.LanguageCode == "multi" && t.IdLanguage == 0).Any() ? translations.Where(t => t.LanguageCode == "multi" && t.IdLanguage == 0).FirstOrDefault().Translation.Copy() : null); template.Translations = translations.Where(t => !(t.LanguageCode == "multi" && t.IdLanguage == 0) && t.IsValid).Select(t => new lm.Comol.Core.Mail.Messages.dtoBaseMailTemplateContent() { IdLanguage = t.IdLanguage, LanguageCode = t.LanguageCode, LanguageName = t.LanguageName, Translation = t.Translation }).ToList(); } Boolean sent = OtherModuleService.SendMail(CurrentManager.GetPerson(UserContext.CurrentUserID), smtpConfig, template.MailSettings, messages, ref rSkipped, template, View.CurrentObject, View.ModuleCode); Int32 removed = rSkipped.Count + messages.SelectMany(m => m.RemovedRecipients).Count(); View.DisplayMessageSentTo(messages.SelectMany(m => m.Recipients).Count() - rSkipped.Count, removed); } } }
public void InitInternalView(String languageCode, lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation content, SmtpServiceConfig smtpConfig, String recipients = "", List <String> modules = null, MessageSettings settings = null, Int32 idCommunity = -1, ModuleObject obj = null) { View.DisplayOtherRecipients = false; InitView(PreviewMode.MailToSend, languageCode, content, smtpConfig, recipients, modules, settings, idCommunity, obj); }
public Boolean SendMail(String senderName, String senderMail, String subject, String body, String recipients, MessageSettings settings, SmtpServiceConfig smtpConfig) { Boolean result = false; try { //List<System.Net.Mail.MailAddress> rItems = new List<System.Net.Mail.MailAddress>(); //if (!String.IsNullOrEmpty(recipients)){ // rItems.AddRange(recipients.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList().Select(m => new System.Net.Mail.MailAddress(m)).ToList()); //} //string separator, Language dLanguage = CurrentManager.GetDefaultLanguage(); lm.Comol.Core.Mail.MailService mailService = new lm.Comol.Core.Mail.MailService(smtpConfig, settings); lm.Comol.Core.Mail.dtoMailMessage message = new lm.Comol.Core.Mail.dtoMailMessage(subject, body); message.FromUser = new System.Net.Mail.MailAddress(senderMail, senderMail); mailService.SendMail(UserContext.Language.Id, dLanguage, message, recipients, MailCommons.Domain.RecipientType.BCC); result = true; } catch (Exception ex) { } return(result); }
public void InitView(PreviewMode pMode, String languageCode, lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation content, SmtpServiceConfig smtpConfig, String recipients = "", List <String> modules = null, MessageSettings settings = null, Int32 idCommunity = -1, ModuleObject obj = null) { View.DisplayOptions = (pMode == PreviewMode.MailSent); Person person = CurrentManager.GetPerson(UserContext.CurrentUserID); if (!UserContext.isAnonymous && person != null) { View.isInitialized = true; switch (pMode) { case PreviewMode.TemplateDisplay: case PreviewMode.MailToSend: if (String.IsNullOrEmpty("recipients")) { recipients = person.Mail; } View.AllowSendMail = settings != null && View.AllowSendMail && (View.EditAddressTo || !String.IsNullOrEmpty(recipients)); Language dLanguage = CurrentManager.GetDefaultLanguage(); Language language = CurrentManager.GetLanguageByCodeOrDefault(languageCode, true); if (modules != null) { String organizationName = ""; Community community = null; if (idCommunity > 0) { community = CurrentManager.GetCommunity(idCommunity); if (community != null) { organizationName = CurrentManager.GetOrganizationName(community.Id); } } if (community != null && idCommunity > 0) { content = View.ParseContent((language == null) ? 0 : language.Id, languageCode, content, modules, community, person, organizationName, obj); } else { content = View.ParseContent((language == null) ? 0 : language.Id, languageCode, content, modules, idCommunity, (community == null || idCommunity < 1) ? View.GetPortalName((language != null) ? language.Id : 0) : community.Name, person, organizationName, obj); } } if (settings != null) { dtoMailMessagePreview dtoContent = new dtoMailMessagePreview((language != null) ? language.Id : 0, dLanguage, new dtoMailMessage() { UserSubject = content.Subject, Body = content.Body }, settings, smtpConfig); View.LoadPreviewTemplateMessage(pMode, dtoContent, recipients); } else { View.LoadPreviewTemplateMessage(pMode, content); } break; } } else { View.HideContent(); } }
public void InitView(PreviewMode pMode, String languageCode, lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation content, SmtpServiceConfig smtpConfig, String recipients = "", List <String> modules = null, List <lm.Comol.Core.TemplateMessages.Domain.ChannelSettings> notifications = null, Int32 idCommunity = -1, ModuleObject obj = null) { InitView(pMode, languageCode, content, smtpConfig, recipients, modules, (notifications != null && notifications.Where(n => n.Channel == lm.Comol.Core.Notification.Domain.NotificationChannel.Mail).Any()) ? notifications.Where(n => n.Channel == lm.Comol.Core.Notification.Domain.NotificationChannel.Mail).Select(n => n.MailSettings).FirstOrDefault() : null, idCommunity, obj); }
private void InternalSendMail(string istanceIdentifier, int idUser, int idCommunity, string moduleCode, SmtpServiceConfig cfg, Message message, string attachmentPath = "", bool saveMessage = false, string attachmentSavedPath = "") { IstanceConfig istance = Config.GetIstanceConfiguration(istanceIdentifier); if (cfg != null && istance != null) { using (ISession session = lm.Comol.Core.Data.SessionDispatcher.NewSession(istance.ConnectionString)) { if (session != null) { using (InternalMailService service = new InternalMailService(cfg, istance, session)) { Boolean result = false; String messagePath = service.GetAttachmentsFullPath(istance.AttachmentUploadPath, attachmentPath); try { result = service.SendMail(idUser, idCommunity, moduleCode, message, (message.Settings.IsBodyHtml), messagePath, saveMessage, attachmentSavedPath); } catch (Exception ex) { ErrorHandler.addMessageToPoisonQueue(ex, message); } } } else { ErrorHandler.addMessageToPoisonQueue(message); } } } }
public void SendMailWithSettings(string istanceIdentifier, int idUser, int idCommunity, string moduleCode, SmtpServiceConfig config, Message message, string attachmentPath = "", bool saveMessage = false, string attachmentSavedPath = "") { InternalSendMail(istanceIdentifier, idUser, idCommunity, moduleCode, config, message, attachmentPath, saveMessage, attachmentSavedPath); }
public ProdSmtpServer(SmtpServiceConfig SmtpServiceConfig) : base(SmtpServiceConfig) { }
public MailService(SmtpServiceConfig smtp, lm.Comol.Core.MailCommons.Domain.Messages.MessageSettings settings) { SMTPconfig = smtp; MailSettings = settings; }
public SmtpServiceBase(SmtpServiceConfig SmtpServiceConfig) { _SmtpServiceConfig = SmtpServiceConfig; }
public MockedSmtpService(SmtpServiceConfig SmtpServiceConfig) : base(SmtpServiceConfig) { }
public FastSmtpService(SmtpServiceConfig SmtpServiceConfig) : base(SmtpServiceConfig) { }