コード例 #1
0
ファイル: MimeMessage.cs プロジェクト: pengyancai/cs-util
        public static MimeMessage CreateMultipart(IEnumerable<MimeMessage> subParts)
        {
            var message = new MimeMessage(subParts);

              message.Boundary = string.Format("----------------{0:D16}", DateTime.Now.Ticks);
              message.MimeType = MimeType.MultipartMixed;

              message.WriteContent("This is a multi-part message in MIME format.", ContentTransferEncodingMethod.SevenBit, Encoding.ASCII);

              return message;
        }
コード例 #2
0
ファイル: MimeMessage.cs プロジェクト: pengyancai/cs-util
        public static MimeMessage CreateAttachment(Stream contentStream, MimeType mimeType, string filename, string description, bool inline)
        {
            if (contentStream == null)
            throw new ArgumentNullException("contentStream");
              if (mimeType == null)
            throw new ArgumentNullException("mimeType");

              var disposition = inline ? MimeMessageDisposition.Inline : MimeMessageDisposition.Attachment;

              // TODO: Content-Type + name parameter
              var message = new MimeMessage(new[] {
            MimeHeader.CreateContentType(mimeType, null, null, filename),
            MimeHeader.CreateContentTransferEncoding(ContentTransferEncodingMethod.Base64),
            MimeHeader.CreateContentDisposition(disposition, filename),
            new MimeHeader("Content-Description", description, MimeEncodingMethod.Base64, Charsets.UTF8),
              });

              message.MimeType = mimeType;
              message.Disposition = disposition;

              message.WriteContent(ContentTransferEncodingMethod.Base64, delegate(BinaryWriter writer) {
            contentStream.CopyTo(writer);
              });

              return message;
        }