public Email() { ToRecipients = new ExchangePrincipleCollection(); CcRecipients = new ExchangePrincipleCollection(); BccRecipients = new ExchangePrincipleCollection(); BodyType = EmailBodyType.Text; }
public void AddBody(string stringBody, List <string> linkedResourcesPathList, EmailBodyType emailBodyType) { EmailBodyType = emailBodyType; foreach (var item in linkedResourcesPathList) { var resouce = MessageBuilder.LinkedResources.Add(item); resouce.ContentId = MimeUtils.GenerateMessageId(); } switch (emailBodyType) { case EmailBodyType.HtmlText: MessageBuilder.HtmlBody = stringBody; foreach (var res in linkedResourcesPathList) { if (File.Exists(res)) { MessageBuilder.LinkedResources.Add(res); } } //linkedResourcesPathList.Any() ? string.Format(stringBody, MessageBuilder.LinkedResources.Select(l => l.ContentId).ToList()) : stringBody; break; case EmailBodyType.PlainText: MessageBuilder.TextBody = stringBody; break; default: MessageBuilder.TextBody = stringBody; break; } }
private string ParseEmailBodyType(EmailBodyType emailBodyType) { return(emailBodyType switch { EmailBodyType.Plain => "plain", EmailBodyType.Html => "html", _ => throw new ArgumentException(nameof(EmailBodyType)) });
public EmailMessage(string subject, string senderName, string emailFrom, List <string> emailDestinationList) { MailMessage = new MimeMessage(); EmailBodyType = EmailBodyType.PlainText; Subject = subject; From = emailFrom; SenderName = senderName; To = emailDestinationList; AttachmentList = new List <MimePart>(); MessageBuilder = new BodyBuilder(); }
public override void LoadFromTGSerializedObject(TGSerializedObject _tgs) { base.LoadFromTGSerializedObject(_tgs); From = _tgs.GetString("From"); To = _tgs.GetString("To"); ReplyTo = _tgs.GetString("ReplyTo"); Body = _tgs.GetString("Body"); Subject = _tgs.GetString("Subject"); BodyType = (EmailBodyType)Enum.Parse(typeof(EmailBodyType), _tgs.GetString("BodyType")); }
public string GetEmailTemplet(EmailTemplet emailTemplet, EmailBodyType emailBodyType) { var emailTempletName = string.Format("{0}.{1}", emailTemplet, emailBodyType); string emailTempletStr; if (_isCacheEmailTemplet) { emailTempletStr = CacheHelper.GetCache <string>(emailTempletName); if (string.IsNullOrEmpty(emailTempletStr)) { return(GetEmailTempletFromFile(emailTempletName)); } return(emailTempletStr); } return(GetEmailTempletFromFile(emailTempletName)); }
public EmailConfiguration(IList <object> args) { var settings = Program.Configuration.Email; var emailConfigArray = args; if (emailConfigArray.Count != 8) { throw new Exception( $"Incorrect number of email config array items - got {emailConfigArray.Count}, expected 8"); } this.Id = Guid.NewGuid(); this.To = new List <string>(); this.Cc = new List <string>(); this.Bcc = new List <string>(); this.Attachments = new List <string>(); this.From = emailConfigArray[0].ToString(); // just use the first account we find already registered in outlook //if (this.From.Equals("CurrentUser", StringComparison.CurrentCultureIgnoreCase)) //{ // this.From = $"{Environment.UserName}@{System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName}"; //} this.To = ParseEmail(emailConfigArray[1].ToString(), settings.RecipientsToMin, settings.RecipientsToMax); this.Cc = ParseEmail(emailConfigArray[2].ToString(), settings.RecipientsCcMin, settings.RecipientsCcMax); this.Bcc = ParseEmail(emailConfigArray[3].ToString(), settings.RecipientsBccMin, settings.RecipientsBccMax); var emailContent = new EmailContentManager(); this.Subject = emailConfigArray[4].ToString(); if (this.Subject.Equals("random", StringComparison.InvariantCultureIgnoreCase)) { this.Subject = emailContent.Subject; } this.Body = emailConfigArray[5].ToString(); if (this.Body.Equals("random", StringComparison.InvariantCultureIgnoreCase)) { this.Body = emailContent.Body; this.Body += $"{Environment.NewLine}{Environment.NewLine}CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, may contain information that is protected by the DoD Privacy Act. This e-mail transmission is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that you are not authorized to read, print, retain, copy, disclose, distribute, or use this message, any part of it, or any attachments. If you have received this message in error, please immediately notify the sender by telephone or return e-mail and delete this message and any attachments from your system without reading or saving in any manner. You can obtain additional information about the DoD Privacy Act at http://dpclo.defense.gov/privacy. Thank you.{Environment.NewLine}Timestamp: {DateTime.Now} ID: {this.Id}"; } this.BodyType = EmailBodyType.PlainText; if (!string.IsNullOrEmpty(emailConfigArray[6].ToString())) { emailConfigArray[6] = emailConfigArray[6].ToString().Trim(); if (emailConfigArray[6].ToString().Equals("HTML", StringComparison.InvariantCultureIgnoreCase)) { this.BodyType = EmailBodyType.HTML; } else if (emailConfigArray[6].ToString().Equals("RTF", StringComparison.InvariantCultureIgnoreCase)) { this.BodyType = EmailBodyType.RTF; } } if (!string.IsNullOrEmpty(emailConfigArray[7].ToString())) { var a = emailConfigArray[7].ToString().Split(Convert.ToChar(",")); foreach (var o in a) { if (File.Exists(o)) { this.Attachments.Add(o); } else { _log.Debug($"Can't add attachment {o} - file was not found"); } } } }
/// <summary> /// 单一发信接口模型 /// </summary> /// <param name="toAddress"></param> /// <param name="emailBodyType"></param> /// <param name="emailTemplet"></param> public SingleSendMailModel(string toAddress, EmailBodyType emailBodyType = EmailBodyType.Html, EmailTemplet?emailTemplet = null) { _toAddress = toAddress; _emailBodyType = emailBodyType; _emailTemplet = emailTemplet ?? GetDefaultEmailTemplet(); }