public String CreateBodyText(MailMessage message) { var bodyText = message.BodyHtml; StringBuilder sb = new StringBuilder(bodyText.Length + 200); sb.AppendLine("<hr>"); sb.AppendFormat("Subject: {0}<br />", message.Subject).AppendLine(); if (message.From != null) { sb.AppendFormat("From: {0}<br />", message.From.ToString()).AppendLine(); } if (message.Headers["Date"] != null) { sb.AppendFormat("Date: {0}<br />", message.Headers["Date"]).AppendLine(); } Int32 count = message.To.MailAddresses.Count; if (count > 0) { sb.Append("To: "); for (int i = 0; i < count; i++) { var m = message.To.MailAddresses[i]; sb.Append(m.ToString()); if (i < count - 1) { sb.Append("; "); } } sb.AppendLine("<br />"); } sb.AppendLine("<br />"); sb.Append(bodyText); return sb.ToString(); }
public String CreateBodyText(MailMessage message) { var bodyText = message.BodyText; StringBuilder sb = new StringBuilder(bodyText.Length + 200); StringReader sr = new StringReader(bodyText); sb.AppendLine("________________________________"); sb.AppendFormat("> Subject: {0}", message.Subject).AppendLine(); if (message.From != null) { sb.AppendFormat("> From: {0}", message.From.ToString()).AppendLine(); } if (message.Headers["Date"] != null) { sb.AppendFormat("> Date: {0}", message.Headers["Date"]).AppendLine(); } Int32 count = message.To.MailAddresses.Count; if (count > 0) { sb.Append("> To: "); for (int i = 0; i < count; i++) { var m = message.To.MailAddresses[i]; sb.Append(m.ToString()); if (i < count - 1) { sb.Append("; "); } } sb.AppendLine(); } sb.AppendLine("> "); while (true) { var line = sr.ReadLine(); sb.Append("> "); sb.AppendLine(line); if (sr.Peek() == -1) { break; } } return sb.ToString(); }
public string GetTrubleMessageText(string sender, string subject, DateTime localDate) { string result = null; string server = ImapServer; try { using (HigLabo.Net.Imap.ImapClient cl = new HigLabo.Net.Imap.ImapClient(server)) { cl.UserName = Email; cl.Password = Password; cl.Port = ImapPort; cl.Ssl = ImapSSL; var bl = cl.Authenticate(); if (bl == true) { ImapFolder folder = cl.SelectFolder("INBOX"); SearchResult list = cl.ExecuteSearch("UNSEEN UNDELETED"); HigLabo.Mime.MailMessage mg = null; for (int i = 0; i < list.MailIndexList.Count; i++) { mg = cl.GetMessage(list.MailIndexList[i]); if (mg.Date.LocalDateTime == localDate && mg.From.Value.Equals(sender) && mg.Subject.Trim().Equals(subject)) { break; } } if (mg != null && mg.BodyText != null) { result = mg.BodyText; } } } } catch (Exception e) { logger.Error("Ошибка при повторной загрузке текста сообщения с почтового ящика " + (Email ?? "") + ".\r\nАдрес сервера:" + (server ?? "") + ".\r\nУдаленный порт: " + ImapPort + "\r\nШифрование:" + (ImapSSL ? "Включено" : "Выключено") + "\r\nТекст ошибки:", e); } return(result); }
public String CreateSubject(MailMessage message) { return String.Format("Fw: {0}", message.Subject); }
public String CreateBodyText(MailMessage message) { return message.BodyText; }
private static void AddMailAddress(MailMessage message, MailAddressCreateCondition condition, List<MailAddress> target) { Func<MailAddress, MailAddress, Boolean> f = (x, y) => String.Equals(x.Value, y.Value, StringComparison.OrdinalIgnoreCase); if (condition.UseFrom == true && message.From != null) { target.AddIfNotExist(new MailAddress(message.From.ToString()), f); } if (condition.UseSender == true && message.Sender != null) { target.AddIfNotExist(new MailAddress(message.Sender.ToString()), f); } if (condition.UseTo == true) { foreach (var item in message.To.MailAddresses) { var m = MailAddress.TryCreate(item.ToString()); if (m == null) { continue; } target.AddIfNotExist(m, f); } } if (condition.UseCc == true) { foreach (var item in message.Cc.MailAddresses) { var m = MailAddress.TryCreate(item.ToString()); if (m == null) { continue; } target.AddIfNotExist(m, f); } } if (condition.ExcludeSender == true) { target.RemoveAll(el => el.Value == condition.Sender.Value); } }
public static SmtpMessage Create(MailMessage message, SmtpMessageCreateCondition condition) { SmtpMessage mg = new SmtpMessage(); mg.Subject = condition.SubjectFormatter.CreateSubject(message); mg.From = condition.Sender; mg.Sender = condition.Sender; mg.ContentType.SetProperty(message.ContentType); mg.ContentTransferEncoding = message.ContentTransferEncoding; if (condition.BodyFormatter.IsHtml == true) { mg._BodyTextContent.LoadHtml(condition.BodyFormatter.CreateBodyText(message)); } else { mg.BodyText = condition.BodyFormatter.CreateBodyText(message); } AddMailAddress(message, condition.To, mg.To); AddMailAddress(message, condition.Cc, mg.Cc); AddMailAddress(message, condition.Bcc, mg.Bcc); if (condition.CopyContents == true) { foreach (var item in message.Contents) { var ct = new SmtpContent(); ct.LoadData(item.RawData); ct.ContentType.SetProperty(item.ContentType); ct.ContentDisposition.SetProperty(item.ContentDisposition); mg.Contents.Add(ct); } } return mg; }
public static SmtpMessage Create(MailMessage message, MailAddress sender, SmtpMessageCreateMode mode, Boolean isBodyHtml) { return Create(message, new SmtpMessageCreateCondition(sender, mode, isBodyHtml)); }
public static SmtpMessage Create(MailMessage message) { var m = MailAddress.TryCreate(message.From.ToString()); return Create(message, new SmtpMessageCreateCondition(m, SmtpMessageCreateMode.Copy, false)); }