MimeKit.MimeMessage.Load C# (CSharp) Method

Load() public static method

Load a MimeMessage from the specified file.
Loads a MimeMessage from the file at the given path, using the specified ParserOptions.
/// is null. /// -or- /// is null. /// /// is a zero-length string, contains only white space, or /// contains one or more invalid characters as defined by /// . /// /// is an invalid file path. /// /// The specified file path could not be found. /// /// The user does not have access to read the specified file. /// /// The operation was canceled via the cancellation token. /// /// There was an error parsing the entity. /// /// An I/O error occurred. ///
public static Load ( ParserOptions options, string fileName, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
options ParserOptions The parser options.
fileName string The name of the file to load.
cancellationToken System.Threading.CancellationToken A cancellation token.
return MimeMessage
		public static MimeMessage Load (ParserOptions options, string fileName, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (options == null)
				throw new ArgumentNullException (nameof (options));

			if (fileName == null)
				throw new ArgumentNullException (nameof (fileName));

			using (var stream = File.Open (fileName, FileMode.Open, FileAccess.Read))
				return Load (options, stream, cancellationToken);
		}

Same methods

MimeMessage::Load ( ParserOptions options, Stream stream, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( ParserOptions options, Stream stream, bool persistent, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( Stream stream, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( Stream stream, bool persistent, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( string fileName, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage

Usage Example

Example #1
0
        MimeEntity CreateAttachment(ContentType contentType, string path, Stream stream)
        {
            var        fileName = GetFileName(path);
            MimeEntity attachment;

            if (contentType.IsMimeType("message", "rfc822"))
            {
                var message = MimeMessage.Load(stream);

                attachment = new MessagePart {
                    Message = message
                };
            }
            else
            {
                MimePart part;

                if (contentType.IsMimeType("text", "*"))
                {
                    // TODO: should we try to auto-detect charsets if no charset parameter is specified?
                    part = new TextPart(contentType);
                }
                else
                {
                    part = new MimePart(contentType);
                }

                LoadContent(part, stream);
                attachment = part;
            }

            attachment.ContentDisposition          = new ContentDisposition(linked ? ContentDisposition.Inline : ContentDisposition.Attachment);
            attachment.ContentDisposition.FileName = fileName;
            attachment.ContentType.Name            = fileName;

            if (linked)
            {
                attachment.ContentLocation = new Uri(fileName, UriKind.Relative);
            }

            return(attachment);
        }