Пример #1
0
		private string AddLogoAsAttachment(MailMsg msg)
		{
			MemoryStream logoStream = new MemoryStream();
			Resources.dvs_logo.Save(logoStream, ImageFormat.Jpeg);
			logoStream.Position = 0;
			Attachment inline = new Attachment(logoStream, "DVS logo");
			inline.ContentDisposition.Inline = true;
			inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
			inline.ContentType.MediaType = "image/png";
			msg.Attachments.Add(inline);
			inline.ContentId = Guid.NewGuid().ToString().Replace("-", "");
			return inline.ContentId;
		}
Пример #2
0
		private void SendMailInternal(EmailTemplateType emailTemplateType, string emailsTo, Dictionary<string, string> dic = null, string emailsCC = null, string emailFrom = null)
		{
			if (string.IsNullOrWhiteSpace(emailsTo))
				throw new ArgumentNullException("email cannot be null or empty");

			var template = _emailRepository.GetByEmailTemplateType(emailTemplateType);
			StringBuilder body = CreateHTMLMailBody();
			body.Replace(Constants.EmailTemplateKeyWords.MailBody, template.Body);
			StringBuilder subject = new StringBuilder(template.Subject);
			StringBuilder signature = new StringBuilder(template.Signature);
			if (dic != null)
			{
				foreach (var item in dic)
				{
					body.Replace(item.Key, item.Value);
					subject.Replace(item.Key, item.Value);
				}
			}

			MailMsg msg = new MailMsg();

			signature.Replace(Constants.EmailTemplateKeyWords.ContactUsLink, _configManager.WebSiteBaseURL + Constants.WebSiteUrls.ContactUs);

			if (template.Signature.Contains(Constants.EmailTemplateKeyWords.SignatureLogo))
			{
				string contentId = AddLogoAsAttachment(msg);
				signature.Replace(Constants.EmailTemplateKeyWords.SignatureLogo, "cid:" + contentId);
			}

			body.Replace(Constants.EmailTemplateKeyWords.MailSignature, signature.ToString());

			msg.IsBodyHtml = true;
			msg.Body = body.ToString();
			msg.Subject = subject.ToString();
			if (!string.IsNullOrWhiteSpace(emailFrom))
				msg.From = new MailAddress(emailFrom);
			else
				msg.From = new MailAddress(_configManager.EmailFrom);

			if (!string.IsNullOrWhiteSpace(_configManager.AlternativeEmail))
				msg.To.Add(_configManager.AlternativeEmail);
			else
				msg.To.Add(emailsTo);
			if (!string.IsNullOrWhiteSpace(emailsCC) && string.IsNullOrWhiteSpace(_configManager.AlternativeEmail))
				msg.CC.Add(emailsCC);

			msg.Send();

		}