public MailMessageItem ToMailMessageItem(int tenant, string user) { Address fromVerified; if (Validator.ValidateSyntax(From)) { fromVerified = new Address(From, DisplayName); } else { throw new ArgumentException(MailApiResource.ErrorIncorrectEmailAddress .Replace("%1", MailApiResource.FieldNameFrom)); } var messageItem = new MailMessageItem { From = fromVerified.ToString(), FromEmail = fromVerified.Email, To = string.Join(", ", To.ToArray()), Cc = Cc != null?string.Join(", ", Cc.ToArray()) : "", Bcc = Bcc != null?string.Join(", ", Bcc.ToArray()) : "", Subject = Subject, Date = DateTime.Now, Important = Important, HtmlBody = HtmlBody, Introduction = MailMessageItem.GetIntroduction(HtmlBody), StreamId = StreamId, TagIds = Labels != null && Labels.Count != 0 ? new ASC.Mail.Aggregator.Common.Collection.ItemList <int>(Labels) : null, Size = HtmlBody.Length, MimeReplyToId = MimeReplyToId, MimeMessageId = string.IsNullOrEmpty(MimeMessageId) ? MailBoxManager.CreateMessageId() : MimeMessageId }; if (messageItem.Attachments == null) { messageItem.Attachments = new List <MailAttachment>(); } Attachments.ForEach(attachment => { attachment.tenant = tenant; attachment.user = user; }); messageItem.Attachments.AddRange(Attachments); return(messageItem); }
public MailMessageItem ToMailMessageItem(int tennantid, string userid, bool loadAttachments) { Address From_verified; if (Validator.ValidateSyntax(From)) { From_verified = new Address(From, DisplayName); } else { throw new ArgumentException(MailServiceResource.ResourceManager.GetString("ErrorIncorrectEmailAddress").Replace("%1", MailServiceResource.ResourceManager.GetString("FieldNameFrom"))); } List <MailAttachment> internalAttachments = new List <MailAttachment>(); PreprocessHtml(tennantid, internalAttachments); MailMessageItem message_item = new MailMessageItem() { From = From_verified.ToString(), From_Email = From_verified.Email, To = string.Join(", ", To.ToArray()), Cc = Cc != null?string.Join(", ", Cc.ToArray()) : "", Bcc = Bcc != null?string.Join(", ", Bcc.ToArray()) : "", Subject = Subject, Date = DateTime.Now, Important = Important, HtmlBody = HtmlBody, StreamId = StreamId, TagIds = Labels != null && Labels.Count != 0 ? new ItemList <int>(Labels) : null }; message_item.loadAttachments(Attachments.Select(att => CreateAttachment(tennantid, att, loadAttachments)), false); message_item.loadAttachments(internalAttachments.ConvertAll(att => CreateAttachment(tennantid, att, true)), true); return(message_item); }
private void Page_Load(object sender, EventArgs e) { if (IsPostBack) { _allAddressesOk = true; // Initialize To addresses foreach (string em in txtTo.Text.Split(";".ToCharArray())) { try { if (em.Trim().Length != 0) { To.Add(em); } } catch (ArgumentException ae) { string message = ae.Message; _allAddressesOk = false; } } // Initialize Cc addresses foreach (string em in txtCc.Text.Split(";".ToCharArray())) { try { if (em.Trim().Length != 0) { Cc.Add(em); } } catch (ArgumentException ae) { string message = ae.Message; _allAddressesOk = false; } } // Initialize To addresses foreach (string em in txtBcc.Text.Split(";".ToCharArray())) { try { if (em.Trim().Length != 0) { Bcc.Add(em); } } catch (ArgumentException ae) { string message = ae.Message; _allAddressesOk = false; } } // Show error lblEmailAddressesNotOk.Visible = !AllEmailAddressesOk; } else { txtTo.Text = string.Join(";", (string[])To.ToArray(typeof(string))); txtCc.Text = string.Join(";", (string[])Cc.ToArray(typeof(string))); txtBcc.Text = string.Join(";", (string[])Bcc.ToArray(typeof(string))); } }