jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LinkedResource from byte[] or stream - more info please

bobishkindaguy opened this issue · comments

I have the same question as the OP on the issue "LinkedResource from byte[] or stream"

I'm trying to use bodyBuilder Attachment.Add, but there is no file to specify for the "filename" parameter. Did I miss locating an overload that doesn't require a filename?

The 4 examples you indicated in your answer all seem to require specifying a filename.

In my program, when the user uploads an attachment file to the cloud, it is transferred as a byte array, which is then stored in the database, not on the file system.

I prefer not to reference the computer's file system anyway. It's not reliable as a data storage medium. It's nice to safely stow all data in a database row!

Therefore, as the OP suggested, if necessary I will write the byte array to a temporary file on the disk, when it is required at the time of sending the email. Perhaps I can delete and recreate the file each time it is needed, so it will only be needed for a few minutes or hours.

A related issue - I'm not sure if bodyBuilder needs the filename to derive the contentType.

There is a parameter for specifying contentType, but the following didn't work:

bodyBuilder.Attachments.Add ( byte array, new ContentType ( "image" ) )
(air coded)

The fileName parameter is only used to provide a name for the attachment in the email.

It is not used as a path to a file on the file system.

It's also used to derive a mime-type based on the file name extension.

What is the correct syntax for specifying the contentType parameter?

This didn't work:

bodyBuilder.Attachments.Add ( ImageBytes(), new ContentType ( "image" ) )

Well, "image" isn't a mime-type for one.

Secondly, there are no ContentType constructors that take only 1 argument.

http://www.mimekit.net/docs/html/M_MimeKit_ContentType__ctor.htm