kaisellgren / mailer

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.
MIT License
166 stars 86 forks source link

Uint8List attachments #226

Closed biancashouse closed 1 year ago

biancashouse commented 1 year ago

I generate pdfs dynamically, and they are Uint8List. I can't figure out if it is possible to send them (base64encoded?) to the sendinblue api. Any guidance would be appreciated. You send files as attachments, so I guess it must be possible ? Thanks in advance

close2 commented 1 year ago

There is a StreamAttachment class:

I haven't programmed in dart for quite some time. Can you convert the Uint8List to a Stream<List<int>>?

class StreamAttachment extends Attachment {
  final Stream<List<int>> _stream;

  StreamAttachment(this._stream, String contentType, {String? fileName}) {
    this.contentType = contentType;
    this.fileName = fileName;
  }

  @override
  Stream<List<int>> asStream() => _stream;
}
close2 commented 1 year ago

Please reopen, if this doesn't solve your problem.

biancashouse commented 1 year ago

Quite right. Works well. Many thanks. Since flutter web requires CORS headers, I would remove the "web" tick, and instead inform the user they should use a server for sending from web apps. I now use mailer in a Google Cloud Run function. so I can use it from mobile and web. I guess it's more secure anyway, because it avoids having to embed api keys in the app (Google Secrets API)

On Tue, Dec 20, 2022 at 6:32 PM Christian Loitsch @.***> wrote:

There is a StreamAttachment class:

I haven't programmed in dart for quite some time. Can you convert the Uint8List to a Stream<List>?

class StreamAttachment extends Attachment { final Stream<List> _stream;

StreamAttachment(this._stream, String contentType, {String? fileName}) { this.contentType = contentType; this.fileName = fileName; }

@override Stream<List> asStream() => _stream; }

— Reply to this email directly, view it on GitHub https://github.com/kaisellgren/mailer/issues/226#issuecomment-1358947265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFNLRB5YPX3WS6QZEMUMZTWOFOJNANCNFSM6AAAAAATEERUHM . You are receiving this because you authored the thread.Message ID: @.***>

-- Ian White h: +61 2 8926 2139 m: +61 404 950 122

close2 commented 1 year ago

This library doesn't work in flutter web. It's technically just not possible.

Is there a way to mark the library unsuitable for flutter web?

biancashouse commented 1 year ago

In actual fact, I think you will find some companies, such as ClickSend, don't require CORS headers with their API key, so perhaps that is why flutter web is checked.

It's safer to assume that such companies will eventually close that loophole.

A real benefit to moving your email send function to a server is that your API key won't be embedded in your mobile or web app.

On Wed, 4 Jan 2023 at 21:12, Christian Loitsch @.***> wrote:

This library doesn't work in flutter web. It's technically just not possible.

Is there a way to mark the library unsuitable for flutter web?

— Reply to this email directly, view it on GitHub https://github.com/kaisellgren/mailer/issues/226#issuecomment-1370729389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFNLRB3GGKPIFUPNGJZMBLWQVEHBANCNFSM6AAAAAATEERUHM . You are receiving this because you authored the thread.Message ID: @.***>

-- Ian White h: +61 2 8926 2139 m: +61 404 950 122