示例#1
0
		private static void AppendAttachments(Mail mail, StringBuilder sb) {
			string uniqueBoundary = GenerateUniqueBoundary();
			sb.Append("MIME-Version: 1.0\r\n");
			sb.Append("Content-Type: multipart/mixed; boundary=\"");
			sb.Append(uniqueBoundary);
			sb.Append("\"\r\n\r\n");
			sb.Append("This is a multi-part message in MIME format.\r\n");
			sb.Append("--");
			sb.Append(uniqueBoundary);
			sb.Append("\r\n");

			AppendBody(mail, sb, false);

			foreach(Attachment attachment in mail.Attachments) {
				byte[] binaryData;
				sb.Append("--");
				sb.Append(uniqueBoundary);
				sb.Append("\r\n");
				sb.Append("Content-Type: ");
				sb.Append(attachment.ContentType);
				sb.Append("\r\n");
				sb.Append("Content-Transfer-Encoding: base64\r\n");
				sb.Append("Content-Disposition: attachment; filename=");
				sb.Append(attachment.FileName);
				sb.Append("\r\n");
				sb.Append("\r\n");
				using(Stream fileStream = attachment.OpenRead()) {
					binaryData = new Byte[fileStream.Length];
					fileStream.Read(binaryData, 0, (int)fileStream.Length);
				}
				string base64String = Convert.ToBase64String(binaryData, 0, binaryData.Length);
				ChunkString(sb, base64String, 73);
				sb.Append("\r\n");
			}
			sb.Append("--");
			sb.Append(uniqueBoundary);
			sb.Append("--\r\n");
		}
示例#2
0
		/// <summary>
		/// Returns instance of MailSender.
		/// </summary>
		public static MailSender CreateMailSender(Mail mail) {
			MailCollection arrList = new MailCollection();
			arrList.Add(mail);
			return new MailSenderImpl(arrList);
		}
示例#3
0
		private static void AppendHeaders(Mail mail, StringBuilder sb) {

			AppendSender(sb, mail.From, "From");
			AppendSender(sb, mail.ReplyTo, "Reply-To");

			if(!mail.SenderHidden && mail.Sender != null && !mail.Sender.Equals(mail.From))
				AppendSender(sb, mail.Sender, "Sender");

			AppendRecivers(sb, mail.To, "To");
			AppendRecivers(sb, mail.CC, "Cc");

			DateTime now = DateTime.Now;
			sb.Append("Date: ");
			sb.Append(now.ToString("ddd, dd MMMM yyyy HH:mm:ss ", DateTimeFormatInfo.InvariantInfo));
			sb.Append(now.ToString("zzzz", DateTimeFormatInfo.InvariantInfo).Replace(":", string.Empty));
			sb.Append("\r\n");
			sb.Append("Subject: ");
			if(!string.IsNullOrEmpty(mail.Subject))
				sb.Append(EncodeHeaderValue(mail.Subject));
			sb.Append("\r\n");
			sb.Append("X-Mailer: nJupiter SMTP-Client V");
			sb.Append(typeof(Mail).Assembly.GetName().Version.ToString());
			sb.Append("\r\n");
			//TODO: fold header values (insert crlf after 78 chars, then continue the same way)
			foreach(string key in mail.Headers.AllKeys) {
				sb.Append(key + ": " + mail.Headers[key]);
				sb.Append("\r\n");
			}
		}
示例#4
0
		private static void AppendBody(Mail mail, StringBuilder sb, bool addMimeHeader) {
			if(addMimeHeader)
				sb.Append("MIME-Version: 1.0\r\n");
			if(mail.Format.Equals(MailFormat.TextAndHtml)) {
				string uniqueBoundary = GenerateUniqueBoundary();
				sb.Append("Content-Type: multipart/alternative; boundary=\"");
				sb.Append(uniqueBoundary);
				sb.Append("\"\r\n\r\n");
				if(addMimeHeader)
					sb.Append("This is a multi-part message in MIME format.\r\n");
				sb.Append("--");
				sb.Append(uniqueBoundary);
				sb.Append("\r\n");
				if(!string.IsNullOrEmpty(mail.AlternativeMessage))
					AppendMessage(sb, mail.AlternativeMessage, "plain", mail.AlternativeMessageEncoding);
				else
					AppendMessage(sb, StripHtmlFromMessage(mail.Message), "plain", mail.MessageEncoding);
				sb.Append("--");
				sb.Append(uniqueBoundary);
				sb.Append("\r\n");
				AppendMessage(sb, mail.Message, "html", mail.MessageEncoding);
				sb.Append("--");
				sb.Append(uniqueBoundary);
				sb.Append("--\r\n");
			} else if(mail.Format.Equals(MailFormat.Html)) {
				AppendMessage(sb, mail.Message, "html", mail.MessageEncoding);
			} else {
				AppendMessage(sb, mail.Message, "plain", mail.MessageEncoding);
			}
		}
示例#5
0
		private static string GenerateMail(Mail mail) {
			StringBuilder sb = new StringBuilder();

			AppendHeaders(mail, sb);

			if(mail.Attachments != null && mail.Attachments.Count > 0) {
				AppendAttachments(mail, sb);
			} else {
				AppendBody(mail, sb, true);
			}
			return sb.ToString();
		}
示例#6
0
		public void CopyTo(Mail[] array, int index) {
			InnerArray.CopyTo(array, index);
		}
示例#7
0
		public bool Contains(Mail mail) {
			return (InnerArray.Contains(mail));
		}
示例#8
0
		public void Remove(Mail mail) {
			InnerArray.Remove(mail);
		}
示例#9
0
		public void Add(Mail mail) {
			InnerArray.Add(mail);
		}