Git Product home page Git Product logo

sendgrid_mailer's Introduction

sendgrid_mailer

sendgrid_mailer is a simple library for composing and sending emails using the SendGrid v3 Mail Send API.

Example

import 'package:sendgrid_mailer/sendgrid_mailer.dart';

main() async {
  final mailer = Mailer('<<YOUR_API_KEY>>');
  final toAddress = Address('[email protected]');
  final fromAddress = Address('[email protected]');
  final content = Content('text/plain', 'Hello World!');
  final subject = 'Hello Subject!';
  final personalization = Personalization([toAddress]);

  final email =
      Email([personalization], fromAddress, subject, content: [content]);
  mailer.send(email).then((result) {
    // ...
  });
}

License

This library is licensed under MIT.

sendgrid_mailer's People

Contributors

dylanshine avatar kazu0620 avatar swdyh avatar larry-cariq avatar

Stargazers

Mohamed Amine  avatar John Lin avatar  avatar N16H7H4WK avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

sendgrid_mailer's Issues

changes on version 0.1.2

Hi, there's a change on the version 0.1.2? Now the Email class has named parameters?
Screen Shot 2020-10-08 at 09 16 48

I was using just like the example on the readme but suddenly it start to throw an error about the Email class expecting 3 parameters but it was getting 4.

Can you please update the readme? Thanks

Error after sending in flutter web

Hey I love this plugin and I use it In iOS and macOS with no problems, but when I send using WEB I can send but receive this error.

`Performing hot restart...
Waiting for connection from debug service on Chrome...
Restarted application in 766ms.
Error: XMLHttpRequest error.
    dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28                get current
packages/http/src/browser_client.dart 71:22                                       <fn>
dart-sdk/lib/async/zone.dart 1612:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 152:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 704:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 733:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 530:7                                         [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58                              <fn>


    at Object.createErrorWithStack (http://localhost:57621/dart_sdk.js:5044:12)
    at Object._rethrow (http://localhost:57621/dart_sdk.js:37476:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:57621/dart_sdk.js:37472:13)
    at Object._microtaskLoop (http://localhost:57621/dart_sdk.js:37332:13)
    at _startMicrotaskLoop (http://localhost:57621/dart_sdk.js:37338:13)
    at http://localhost:57621/dart_sdk.js:33109:9
`

This is the code I use for sending :

`import 'import.dart';
import 'package:flutter/cupertino.dart';

class EmailSender {
  EmailSender({required this.address, required this.message});

  final String address;
  final String message;
  final mailer = Mailer(
      'SG.API');

 
  bool sendMail() {
    final toAddress = Address('$address');
    final fromAddress = Address('my address);
    final content = Content('text/plain', '$message');
    final subject = 'SUBJECT';
    final personalization = Personalization(
      [toAddress],
      //cc: [fromAddress],
    );
    bool resultValue = false;

    final email = Email(
      [personalization],
      fromAddress,
      subject,
      content: [content],
      //attachments: [attachments],
    );
    mailer.send(email).then((result) {
      print(result.hashCode);
      print('VALUE ${result.isValue}');
      //print(result.asValue.value);
      print('ERROR ${result.isError}');
      result.isError ? print(result.asError!.error) : print('');
      if (result.isValue) {
        resultValue = true;
      } else if (result.isError) {
        resultValue = false;
      }
    });
    return resultValue;
  }
}

class EmailSenderError extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      title: Text(
        'Errore invio email',
      ),
      content: Column(
        children: [
          Text(
            'L\'email non e\' stata inviata a causa di un errore. Verifica l\'inirizzo email o la tua connessione a internet.',
          ),
        ],
      ),
      actions: <Widget>[
        TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text(
              'Capito',
              style: TextStyle(color: CupertinoColors.destructiveRed),
            )),
      ],
    );
  }
}
`

How can I fix the code to make it work properly as in the other platform?
Thank you so much!

Error when trying to send email on dev environment

Hi, first thank you for creating this package,
I was successfully sending emails when I was testing on my develop environment, but when I tested on my prod environment I started to get error, the only difference from the environments are different firestore databases.
Do you know what might be the problem?

In lib/src/models/email.dart, typo in toJson() breaks custom args.

See correction below. This should be a simple fix if someone wants to do a pull request.

Map<String, dynamic> toJson() => <String, dynamic>{
'personalizations': personalizations.map((e) => e.toJson()).toList(),
'from': from.toJson(),
'reply_to': replyTo?.toJson(),
'subject': subject,
'content': content?.map((e) => e.toJson()).toList(),
'attachments': attachments?.map((e) => e.toJson()).toList(),
'template_id': templateId,
'headers': headers,
'categories': categories,
'custom_args': customArgs,
'send_at': sendAt?.toUtc().millisecondsSinceEpoch,
'batch_id': batchId,
'asm': asm?.toJson(),
'ip_pool_name': ipPoolName,
'mail_settings': mailSettings?.toJson(),
'tracking_settings': trackingSettings?.toJson(),
};

XMLHttpRequest error

I've tested my Sendgrid parameters with Postman: they work fine.

However, in Flutter for web, these generate an XMLHttpRequest error, using the readme example.

Is this related with the fact that my prototype is currently working in localhost?

update the package

Hi, is there any plans to update the package?
I was updating my project to use flutter sdk 2.0.1 stable, I'm using firestore_storage, and it was require to update the package version, to do that I had to upgrade the http package aswell to ^0.13.0, but doing that I got the error:
Because sendgrid_mailer 0.1.2 depends on http ^0.12.2 and no versions of sendgrid_mailer match >0.1.2 <0.2.0, sendgrid_mailer ^0.1.2 requires http ^0.12.2.
Since the package depends on http ^0.12.2., I can't update the project.

Make subject optional

When using dynamic templates, the subject is already set. Therefore there is no need of setting the subject again.

XMLHttpRequest error on Flutter Web

Getting XMLHttpRequest error when sending email from flutter web on iMac.

I even tried adding headers but didnt work out
headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}

Not working in the Web

I ran into the same error as "XMLHttpRequest error in Flutter Web".
Could you please write in the description that it is not working on the web?
Would have saved me hours...

XMLHttpRequest error

It gives error of XMLHttpRequest in flutter web app. Working fine in mobile app.

HTML Email Example

Can someone please provide an example to send HTML Email? Do the tags go directly into the content? How do you define HTML as the type of email?
thx

getting crash on flutter web

I copy-pasted an example, added my own api key and got this when tried to run it on Flutter web (chrome)

Error: XMLHttpRequest error.
    dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28                get current
packages/http/src/browser_client.dart 71:22                                       <fn>
dart-sdk/lib/async/zone.dart 1687:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 155:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 707:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 736:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 533:7                                         [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37308:58                              <fn>


    at Object.createErrorWithStack (http://localhost:57452/dart_sdk.js:5062:12)
    at Object._rethrow (http://localhost:57452/dart_sdk.js:37680:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:57452/dart_sdk.js:37676:13)
    at Object._microtaskLoop (http://localhost:57452/dart_sdk.js:37533:13)
    at _startMicrotaskLoop (http://localhost:57452/dart_sdk.js:37539:13)
    at http://localhost:57452/dart_sdk.js:33289:9

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 2.3.0-1.0.pre, on Mac OS X 10.15.7 19H524 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] Connected device (3 available)
    final mailer = Mailer('my api key');
    final toAddress = Address('[email protected]');
    final fromAddress = Address('[email protected]');
    final content = Content('text/plain', 'Hello World!');
    final subject = 'Hello Subject!';
    final personalization = Personalization([toAddress]);

    final email = Email([personalization], fromAddress, subject, content: [content]);
    mailer.send(email).then((result) {
      print('----------------------- $result');
    });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.