+1 vote

Hi,

My VB.NET code currently receives a mail structure via REST (as a post to my code) and I receive the attachment I need to send as mime64 encoded.

Using the SMTP library, how do I use the mailbuilder to create the attachment from my base64 string, and not get it from a file.
Seems like builder only allows read from file for attachment?

builder.AddAttachment(path as string)

I don't want to have to create a temporary file, then read that file just to send an email with an attachment.

Is there any way around this?

thanks

Andy.

by (650 points)

1 Answer

0 votes
 
Best answer

Yo can create attachment from in-memory data using Mail.dll, there is no need to create a temporary file:

C#:

byte[] data = new byte[] {1, 2, 3};

MailBuilder builder = new MailBuilder();
MimeData att = builder.AddAttachment(data);
att.FileName = "report.pdf";
IMail email = builder.Create();

VB.NET:

Dim data As Byte() = New Byte() {1, 2, 3}

Dim builder As MailBuilder = New MailBuilder()
Dim att As MimeData = builder.AddAttachment(data)
att.FileName = "report.pdf"
Dim email As IMail = builder.Create()

Although it would be possible to use base64 encoded data you get from your REST API, I think you shouldn't do that.

The reason behind this is, that emails should respect line limits, which might or might not be respected by your API's clients when the encode data.

Decode Base64 you get from the API, and allow Mail.dll to encode it again.

by (297k points)
selected by
...