public MailMessage ToMailMessage() { MailMessage mailMessage = null; if (IsValid) { mailMessage = new MailMessage { From = (EmailAddress)From, Subject = Subject, Body = Body, IsBodyHtml = IsBodyHtml, }; if (!To.IsEmpty()) { To.ForEach(e => mailMessage.To.Add(e)); } if (!Bcc.IsEmpty()) { Bcc.ForEach(e => mailMessage.Bcc.Add(e)); } } return(mailMessage); }
public override void Send() { try { var mail = new MailMessage { From = From, IsBodyHtml = IsBodyHtml, Subject = Subject, BodyEncoding = Encoding.UTF8, Body = Body }; To?.ForEach(address => mail.To.Add(address)); Cc?.ForEach(address => mail.To.Add(address)); Bcc?.ForEach(address => mail.To.Add(address)); var smtpClient = new SmtpClient { Host = Host, Port = Port, EnableSsl = EnableSsl, Credentials = new NetworkCredential(UserName, Password), DeliveryMethod = SmtpDeliveryMethod.Network }; smtpClient.Send(mail); } catch (Exception exception) { throw new Exception(exception.Message); } }
private void read_tos(XmlDocument doc) { XmlNodeList mail_to = doc.DocumentElement.SelectNodes("/config/mail_server/TO"); XmlNodeList mail_cc = doc.DocumentElement.SelectNodes("/config/mail_server/CC"); XmlNodeList mail_bcc = doc.DocumentElement.SelectNodes("/config/mail_server/BCC"); for (int i = 0; i < mail_to.Count; i++) { string txt_to = mail_to.Item(i).InnerText; To.Add(txt_to); console_write("mail to >> " + txt_to); } for (int i = 0; i < mail_cc.Count; i++) { string txt_cc = mail_cc.Item(i).InnerText; Cc.Add(txt_cc); console_write("mail cc >> " + txt_cc); } for (int i = 0; i < mail_bcc.Count; i++) { string txt_bcc = mail_bcc.Item(i).InnerText; Bcc.Add(txt_bcc); console_write("mail bcc >> " + txt_bcc); } }
protected override void Execute(CodeActivityContext context) { Application app = new Application(); app.ActiveWindow(); Outlook.MailItem mail; if (!(TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg"))) { throw new System.Exception("Invalid template format, please use a '.oft' or '.msg' template."); } mail = TemplatePath.Get(context) != ""?(app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem):new MailItem(); mail.Subject = String.IsNullOrEmpty(Subject.Get(context))?(String.IsNullOrEmpty(mail.Subject)?"Untitled":mail.Subject):Subject.Get(context); mail.To = String.IsNullOrEmpty(To.Get(context))?mail.To:To.Get(context); mail.CC = String.IsNullOrEmpty(Cc.Get(context))?mail.CC:Cc.Get(context); mail.BCC = String.IsNullOrEmpty(Bcc.Get(context))?mail.BCC:Bcc.Get(context); if (String.IsNullOrEmpty(mail.To) && String.IsNullOrEmpty(mail.CC) && String.IsNullOrEmpty(mail.BCC)) { throw new System.Exception("Error, there is no recepients specified"); } mail.HTMLBody = mail.HTMLBody.Replace("{message}", Body.Get(context)); mail.HTMLBody = mail.HTMLBody.Replace("{table}", DT.Get(context) != null?(DT.Get(context).Rows.Count > 0?GetHTMLTable(DT.Get(context)):""):""); mail.Send(); app.GetNamespace("MAPI").SendAndReceive(true); var releaseResult = Marshal.ReleaseComObject(app); }
private void SetupMailMessage(MailMessage msg, LogEventInfo logEvent) { msg.From = new MailAddress(From.Render(logEvent)); foreach (var mail in To.Render(logEvent).Split(';')) { msg.To.Add(mail); } if (Bcc != null) { foreach (var mail in Bcc.Render(logEvent).Split(';')) { msg.Bcc.Add(mail); } } if (CC != null) { foreach (var mail in CC.Render(logEvent).Split(';')) { msg.CC.Add(mail); } } msg.Subject = Subject.Render(logEvent); msg.BodyEncoding = Encoding; msg.IsBodyHtml = Html; msg.Priority = MailPriority.Normal; }
//public AttachmentCollection Attachments { get; } //public AlternateViewCollection AlternateViews { get; } private void Load(MailMessage m) { IsBodyHtml = m.IsBodyHtml; Priority = m.Priority; BodyTransferEncoding = m.BodyTransferEncoding; DeliveryNotificationOptions = m.DeliveryNotificationOptions; if (m.Sender != null) { Sender = new MailAddressSerializable(m.Sender.Address, m.Sender.DisplayName); } if (m.From != null) { From = new MailAddressSerializable(m.From.Address, m.From.DisplayName); } foreach (MailAddress a in m.To) { To.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.CC) { CC.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.Bcc) { Bcc.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.ReplyToList) { ReplyToList.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } Subject = m.Subject; Body = m.Body; //output.AlternateViews = input.AlternateViews; //output.Attachments = input.Attachments; }
protected override void Execute(CodeActivityContext context) { String TO, CC, BCC, SUBJECT, BODY; if (TemplatePath.Get(context).Contains(".eml")) { Message emlMessage = ReadMessage(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)); TO = emlMessage.To; CC = emlMessage.CC; BCC = emlMessage.BCC; SUBJECT = emlMessage.Subject; BODY = String.IsNullOrEmpty(emlMessage.HTMLBody)?emlMessage.TextBody:emlMessage.HTMLBody; } else if (TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg")) { try { Outlook.Application app = new Outlook.Application(); Outlook.MailItem template = app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem; TO = template.To; CC = template.CC; BCC = template.BCC; SUBJECT = template.Subject; BODY = String.IsNullOrEmpty(template.HTMLBody) ? template.Body : template.HTMLBody; } catch { throw new System.Exception("Error, .oft and .msg files can only be read if you have Outlook installed, try using a .eml as a template"); } } else { throw new System.Exception("Invalid template format, please use a '.oft', '.msg', or '.eml' template."); } SUBJECT = String.IsNullOrEmpty(Subject.Get(context)) ? (String.IsNullOrEmpty(SUBJECT) ? "Untitled" : SUBJECT) : Subject.Get(context); TO = String.IsNullOrEmpty(To.Get(context)) ? TO : To.Get(context); CC = String.IsNullOrEmpty(Cc.Get(context)) ? CC : Cc.Get(context); BCC = String.IsNullOrEmpty(Bcc.Get(context)) ? BCC : Bcc.Get(context); BODY = BODY.Replace("{message}", String.IsNullOrEmpty(Body.Get(context))?"":Body.Get(context)); BODY = BODY.Replace("{table}", DT.Get(context) != null ? (DT.Get(context).Rows.Count > 0 ? GetHTMLTable(DT.Get(context)) : "") : ""); MailMessage mail = new MailMessage(From.Get(context), TO, SUBJECT, BODY); mail.Bcc.Add(BCC); mail.IsBodyHtml = true; mail.CC.Add(CC); SmtpClient client = new SmtpClient { Port = Port.Get(context), DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = EnableSSL, Host = Server.Get(context), Credentials = new System.Net.NetworkCredential(Email.Get(context), Password.Get(context)), Timeout = 30000 }; client.Send(mail); }
public void TestSearchMailQueryLogicOr(From from, To to, Cc cc, Bcc bcc, Subject subject, Body body, Date date, Box box, Attachment attachment) { var handler = new DefaultManager(); var request = GenerateSearchMailRequest(QueryLogic.Or, from, to, cc, bcc, subject, body, date, box, attachment, Bulked.Missing, DateListSingleMail.ElementAt(NumberOfMail / 2)); var response = handler.Send <Dictionary <string, object> >(SearchEndPoint, JsonConvert.SerializeObject(request), HttpMethod.POST); VerifyDataForFullParams(request, response, QueryLogic.Or, from, to, cc, bcc, subject, body, date, box, attachment); }
private List <Pair> getPlan() { var plan = new List <Pair>(); var web_db = new WebModelContainer(); var emailAccounts = web_db.EmailAccounts.ToList(); int pos = 0; int total = Bcc.Count; foreach (var acct in emailAccounts) { if (!acct.Verified) { continue; } var dailyCount = acct.DailyCounts.Where(d => d.WhichDate == DateTime.Today).SingleOrDefault(); if (dailyCount == null) { dailyCount = new DailyCount { WhichDate = DateTime.Today, Count = 0, EmailAccount = acct, EmailAccountId = acct.Id, }; web_db.DailyCounts.Add(dailyCount); web_db.SaveChanges(); } if (dailyCount.Count >= acct.SmtpDailyLimit) { continue; } var msg = new MailMessage(); int perTimeCount = 0; while ((pos < total) && (dailyCount.Count < acct.SmtpDailyLimit) && (perTimeCount < acct.SmtpPerTimeLimit)) { msg.Bcc.Add(Bcc.ElementAt(pos)); pos++; dailyCount.Count++; perTimeCount++; } msg.Subject = Subject; msg.Body = Body; msg.IsBodyHtml = true; msg.From = new MailAddress(acct.From); plan.Add(new Pair(acct, msg)); if (pos == total) { break; } } web_db.Dispose(); return(plan); }
public IEnumerable <string> Bcc_Email_Addresses() { if (Bcc == null) { return(new string[0]); } return(Bcc.Replace(" ", "").Split(',')); }
string GetTestEmailAccount() { var addresses = new List <string>(); addresses.AddRange(To.Split(';')); addresses.AddRange(Cc.Split(';')); addresses.AddRange(Bcc.Split(';')); return(addresses.FirstOrDefault()); }
public void BccConstructorShouldSetProperties(string emailAddress, string name) { var bcc = new Bcc(new List <Address>() { new Address(emailAddress, name) }); bcc.Addresses.FirstOrDefault().EMail.ShouldBe(emailAddress); bcc.Addresses.FirstOrDefault().Name.ShouldBe(name); }
public void AddBcc(string emailAdress, string displayName) { if (Bcc != null) { Bcc.Add(new MailAddress(emailAdress, displayName)); } else { Bcc = new List <MailAddress> { new MailAddress(emailAdress, displayName) } }; }
private void GetMailMessageBcc(MailMessage message) { var sb = new StringBuilder(0); if (message.Bcc.Count > 0) { foreach (var bcc in message.Bcc) { sb.AppendFormat("{0},", bcc.Address); } Bcc = Bcc.Remove(Bcc.Length - 1, 1); } Bcc = sb.ToString(); }
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 MailMessage Build() { MailMessage mailMessage = new MailMessage(); if (From == null || string.IsNullOrWhiteSpace(From.Address)) { throw new ArgumentException(nameof(From)); } else { mailMessage.From = From; } if (To != null && To.Any()) { mailMessage.To.AddRange(To); } if (CC != null && CC.Any()) { mailMessage.CC.AddRange(CC); } if (Bcc != null && Bcc.Any()) { mailMessage.Bcc.AddRange(Bcc); } if (!string.IsNullOrWhiteSpace(Subject)) { mailMessage.Subject = Subject; } if (!string.IsNullOrWhiteSpace(Body)) { mailMessage.Body = Body; mailMessage.IsBodyHtml = IsBodyHtml; } if (Attachments != null && Attachments.Any()) { mailMessage.Attachments.AddRange(Attachments); } return(mailMessage); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (SavedSource != null ? SavedSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (To != null ? To.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Cc != null ? Cc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Bcc != null ? Bcc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Attachments != null ? Attachments.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Body != null ? Body.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); return(hashCode); } }
//[Category("Output")] //public OutArgument<double> ResultNumber { get; set; } protected override void Execute(CodeActivityContext context) { try { var body = Body.Get(context); var subject = Subject.Get(context); var port = Port.Get(context); var server = Server.Get(context); var email = Email.Get(context); var password = Password.Get(context); var bcc = Bcc.Get(context); var cc = Cc.Get(context); var to = To.Get(context); var from = From.Get(context); var name = Name.Get(context); var inputdirpath = InputDirPath.Get(context); String[] files = Directory.GetFiles(inputdirpath); MailMessage mail = new MailMessage(from, to); mail.Subject = subject; mail.Body = body; foreach (string file in files) { mail.Attachments.Add(new System.Net.Mail.Attachment(file)); } SmtpClient smtp = new SmtpClient(); smtp.Host = server; smtp.Port = port; smtp.Credentials = new NetworkCredential(email, password); smtp.EnableSsl = true; smtp.Send(mail); } catch (Exception e) { Console.WriteLine("Exception Caught at: " + e.Source); Console.WriteLine("Exception Message: " + e.Message); } }
public void SetField(string fieldName, IValue value, InternetMailMessageNonAsciiSymbolsEncodingMode?encodingMode = null) { if (encodingMode == null) { encodingMode = NonAsciiSymbolsEncodingMode; } var stringValue = value.AsString(); headers.Add(fieldName, stringValue); if (fieldName.Equals("BCC", StringComparison.InvariantCultureIgnoreCase)) { Bcc.Add(stringValue); } else if (fieldName.Equals("CC", StringComparison.InvariantCultureIgnoreCase)) { Cc.Add(stringValue); } else if (fieldName.Equals("Date", StringComparison.InvariantCultureIgnoreCase)) { DateTimeOffset res; if (MimeKit.Utils.DateUtils.TryParse(stringValue, out res)) { PostingDate = res.DateTime; PostingDateOffset = new Decimal(res.Offset.TotalSeconds); } } else if (fieldName.Equals("From", StringComparison.InvariantCultureIgnoreCase)) { Sender = value; } else if (fieldName.Equals("Sender", StringComparison.InvariantCultureIgnoreCase)) { SenderName = stringValue; } else if (fieldName.Equals("Subject", StringComparison.InvariantCultureIgnoreCase)) { Theme = stringValue; } }
public virtual void Send() { try { var mail = new MailMessage { From = From, IsBodyHtml = IsBodyHtml, Subject = Subject, BodyEncoding = Encoding.UTF8, Body = Body }; if (To != null) { To.ForEach(address => mail.To.Add(address)); } if (Cc != null) { Cc.ForEach(address => mail.To.Add(address)); } if (Bcc != null) { Bcc.ForEach(address => mail.To.Add(address)); } var smtpClient = new SmtpClient { Host = Host, Port = Port, EnableSsl = EnableSsl, Credentials = new NetworkCredential(UserName, Password), }; smtpClient.Send(mail); } catch (Exception exception) { throw new Exception(exception.Message); } }
public MailMessageBuilder AddRecipient(string address, string name = null, MailAddressType type = MailAddressType.To) { MailAddress mailAddress = new MailAddress(address, name); switch (type) { case MailAddressType.To: To.Add(mailAddress); break; case MailAddressType.CC: CC.Add(mailAddress); break; case MailAddressType.Bcc: Bcc.Add(mailAddress); break; } return(this); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var validationResults = new List <ValidationResult>(); foreach (string email in To) { ValidateEmail(validationResults, email, nameof(To), "To"); } foreach (string email in CC) { ValidateEmail(validationResults, email, nameof(CC), "CC"); } foreach (string email in Bcc) { ValidateEmail(validationResults, email, nameof(Bcc), "BCC"); } if (!To.Any() && !CC.Any() && !Bcc.Any()) { validationResults.Add(new ValidationResult("This email doesn't define a recipient.", new[] { nameof(To) })); } return(validationResults); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (_emailSender != null ? _emailSender.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (_dataObject != null ? _dataObject.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (_password != null ? _password.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (_selectedEmailSource != null ? _selectedEmailSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (FromAccount != null ? FromAccount.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (To != null ? To.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Cc != null ? Cc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Bcc != null ? Bcc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)Priority; hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Attachments != null ? Attachments.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Body != null ? Body.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IsHtml.GetHashCode(); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Converts <see cref="MailMessage"/> to <see cref="System.Net.Mail.MailMessage"/>. /// </summary> /// <returns>A <see cref="System.Net.Mail.MailMessage"/>.</returns> internal System.Net.Mail.MailMessage ToMailMessage() { var mail = new System.Net.Mail.MailMessage(); if (From != null) { mail.From = new MailAddress(From); } To.ForEach(a => mail.To.Add(new MailAddress(a))); ReplyToList.ForEach(a => mail.ReplyToList.Add(new MailAddress(a))); Bcc.ForEach(a => mail.Bcc.Add(new MailAddress(a))); CC.ForEach(a => mail.CC.Add(new MailAddress(a))); foreach (var header in Headers) { mail.Headers[header.Key] = header.Value; } mail.Body = Body; if (BodyEncoding != null) { mail.BodyEncoding = BodyEncoding; } mail.DeliveryNotificationOptions = DeliveryNotificationOptions; mail.IsBodyHtml = IsBodyHtml; if (Sender != null) { mail.Sender = new MailAddress(Sender); } mail.Subject = Subject; if (SubjectEncoding != null) { mail.SubjectEncoding = SubjectEncoding; } mail.Priority = Priority; return(mail); }
public void CheckBNENotBranchWhenEqualToZero() { // BNE <label> // 0110 0110 0000 0110 0x6606 // BNE 6 byte[] data = new byte[] { 0x66, 0x06 }; MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF); state.Condition_Z = true; state.FetchOpCode(); var opcode = new Bcc(state); Assert.That(opcode.Assembly, Is.EqualTo("BNE $0008")); Assert.That(opcode.Size, Is.EqualTo(Size.Byte)); Assert.That(state.PC, Is.EqualTo(0x00000002)); }
//public AttachmentCollection Attachments { get; } //public AlternateViewCollection AlternateViews { get; } private void Load(MailMessage m) { //Headers = new List<JocysCom.ClassLibrary.Collections.KeyValue>(); //foreach (var key in m.Headers.AllKeys) // Headers.Add(new JocysCom.ClassLibrary.Collections.KeyValue(key, m.Headers[key])); IsBodyHtml = m.IsBodyHtml; Priority = m.Priority; BodyTransferEncoding = m.BodyTransferEncoding; DeliveryNotificationOptions = m.DeliveryNotificationOptions; if (m.Sender != null) { Sender = new MailAddressSerializable(m.Sender.Address, m.Sender.DisplayName); } if (m.From != null) { From = new MailAddressSerializable(m.From.Address, m.From.DisplayName); } foreach (MailAddress a in m.To) { To.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.CC) { CC.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.Bcc) { Bcc.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } foreach (MailAddress a in m.ReplyToList) { ReplyToList.Add(new MailAddressSerializable(a.Address, a.DisplayName)); } Subject = m.Subject; Body = m.Body; //output.AlternateViews = input.AlternateViews; //output.Attachments = input.Attachments; }
public Task SendMailTask(AsyncCodeActivityContext context, Receiver reciever, MailMessage mailMessage, CancellationToken cancellationToken, bool isNewMessage, string body) { List <string> attachments = Attachments ?? new List <string>(); foreach (InArgument <string> file in Files) { AddAttachments(attachments, file.Get(context)); } foreach (string item in AttachmentsCollection.Get(context).EmptyIfNull()) { AddAttachments(attachments, item); } string to = To.Get(context); string cc = Cc.Get(context); string bcc = Bcc.Get(context); string sentOnBehalfOfName = SentOnBehalfOfName.Get(context); string account = Account.Get(context); return(Task.Factory.StartNew(delegate { OutlookAPI.SendMail(mailMessage, account, sentOnBehalfOfName, to, cc, bcc, attachments, IsDraft, IsBodyHtml); })); }
public string[] GetDistinctEmails() { var list = new List <string>(); if (To != null && To.Count() > 0) { list.AddRange(To); } if (Cc != null && Cc.Count() > 0) { list.AddRange(Cc); } if (Bcc != null && Bcc.Count() > 0) { list.AddRange(Bcc); } var result = list.Distinct().ToArray(); return(result); }
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); }
public void Save(System.IO.TextWriter txt) { txt.WriteLine("Date: {0}", Date.GetRFC2060Date()); txt.WriteLine("To: {0}", string.Join("; ", To.Select(x => x.ToString()))); txt.WriteLine("Cc: {0}", string.Join("; ", Cc.Select(x => x.ToString()))); txt.WriteLine("Reply-To: {0}", string.Join("; ", ReplyTo.Select(x => x.ToString()))); txt.WriteLine("Bcc: {0}", string.Join("; ", Bcc.Select(x => x.ToString()))); if (Sender != null) { txt.WriteLine("Sender: {0}", Sender); } if (From != null) { txt.WriteLine("From: {0}", From); } if (!string.IsNullOrEmpty(MessageID)) { txt.WriteLine("Message-ID: {0}", MessageID); } var otherHeaders = Headers.Where(x => !SpecialHeaders.Contains(x.Key, StringComparer.InvariantCultureIgnoreCase)); foreach (var header in otherHeaders) { txt.WriteLine("{0}: {1}", header.Key, header.Value); } if (Importance != MailPriority.Normal) { txt.WriteLine("Importance: {0}", (int)Importance); } txt.WriteLine("Subject: {0}", Subject); txt.WriteLine(); //todo: attachments txt.Write(Body); }